Mustache: Making a conditional section show its values.

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Mustache: Making a conditional section show its values.

Offray Vladimir Luna Cárdenas-2
Hi,

I'm using Mustache for a project to build a dynamic distributed web site
generator for public & open data, backed by Fossil and using Material
Design Lite. I have a template like this:

========

{{#twitter}}
              <tr>
                <td
class="mdl-data-table__cell--non-numeric"><b>Twitter</b></td>  
                <td class="mdl-data-table__cell--non-numeric">
                  <a
href="https://twitter.com/{{twitter}}">{{twitter}}</a></td>
              </tr>
{{/twitter}}

========

that is mean to show or hide a row in a table, depending on if Twitter
data for a profile is found in a user profile. When the profile doesn't
have twitter data, the row is hidden, as supposed, and when it has, the
row is shown, but without any actual twitter data. What I'm missing?
Should I use partials in this case and how?

Thanks,

Offray



Reply | Threaded
Open this post in threaded view
|

Re: Mustache: Making a conditional section show its values.

NorbertHartl
Can you show some data you are injecting? It should work as you expect it.

Norbert

> Am 29.05.2017 um 15:26 schrieb Offray Vladimir Luna Cárdenas <[hidden email]>:
>
> Hi,
>
> I'm using Mustache for a project to build a dynamic distributed web site
> generator for public & open data, backed by Fossil and using Material
> Design Lite. I have a template like this:
>
> ========
>
> {{#twitter}}
>              <tr>
>                <td
> class="mdl-data-table__cell--non-numeric"><b>Twitter</b></td>  
>                <td class="mdl-data-table__cell--non-numeric">
>                  <a
> href="https://twitter.com/{{twitter}}">{{twitter}}</a></td>
>              </tr>
> {{/twitter}}
>
> ========
>
> that is mean to show or hide a row in a table, depending on if Twitter
> data for a profile is found in a user profile. When the profile doesn't
> have twitter data, the row is hidden, as supposed, and when it has, the
> row is shown, but without any actual twitter data. What I'm missing?
> Should I use partials in this case and how?
>
> Thanks,
>
> Offray
>
>
>


Reply | Threaded
Open this post in threaded view
|

Re: Mustache: Making a conditional section show its values.

NorbertHartl
To clarify. If the object you inject has a value which either does not contain the key twitter or it does container the key twitter but its value is nil then the section won't be shown.

'{{#twitter}}
             <tr>
               <td
class="mdl-data-table__cell--non-numeric"><b>Twitter</b></td>  
               <td class="mdl-data-table__cell--non-numeric">
                 <a
href="https://twitter.com/{{twitter}}">{{twitter}}</a></td>
             </tr>
{{/twitter}}' asMustacheTemplate value: { #twitter -> nil   } asDictionary

gives empty string in my case.

Norbert
 

> Am 29.05.2017 um 16:20 schrieb Norbert Hartl <[hidden email]>:
>
> Can you show some data you are injecting? It should work as you expect it.
>
> Norbert
>
>> Am 29.05.2017 um 15:26 schrieb Offray Vladimir Luna Cárdenas <[hidden email]>:
>>
>> Hi,
>>
>> I'm using Mustache for a project to build a dynamic distributed web site
>> generator for public & open data, backed by Fossil and using Material
>> Design Lite. I have a template like this:
>>
>> ========
>>
>> {{#twitter}}
>>             <tr>
>>               <td
>> class="mdl-data-table__cell--non-numeric"><b>Twitter</b></td>  
>>               <td class="mdl-data-table__cell--non-numeric">
>>                 <a
>> href="https://twitter.com/{{twitter}}">{{twitter}}</a></td>
>>             </tr>
>> {{/twitter}}
>>
>> ========
>>
>> that is mean to show or hide a row in a table, depending on if Twitter
>> data for a profile is found in a user profile. When the profile doesn't
>> have twitter data, the row is hidden, as supposed, and when it has, the
>> row is shown, but without any actual twitter data. What I'm missing?
>> Should I use partials in this case and how?
>>
>> Thanks,
>>
>> Offray
>>
>>
>>
>
>


Reply | Threaded
Open this post in threaded view
|

Re: Mustache: Making a conditional section show its values.

Offray Vladimir Luna Cárdenas-2
Yes I can share the data. Please load Brea project from [1] and do:

=========

| testUser  |
testUser := BreaMember new createTestUser.
testUser html

=========

[1] http://smalltalkhub.com/#!/~Offray/Brea


You will see that the twitter portion of the row is showed, but without
any actual data inside. You can also try this:

=========
'{{#twitter}}
             <tr>
               <td
class="mdl-data-table__cell--non-numeric"><b>Twitter</b></td>  
               <td class="mdl-data-table__cell--non-numeric">
                 <a
href="https://twitter.com/{{twitter}}">{{twitter}}</a></td>
             </tr>
{{/twitter}}' asMustacheTemplate value: { #twitter -> '@offrayLC'   }
asDictionary
=========

with the same behavior.

I think that the proper output will be the row showed with the data
inside filled.

Let me know how can I help to debug this.

Thanks,

Offray

On 29/05/17 09:26, Norbert Hartl wrote:

> To clarify. If the object you inject has a value which either does not contain the key twitter or it does container the key twitter but its value is nil then the section won't be shown.
>
> '{{#twitter}}
>              <tr>
>                <td
> class="mdl-data-table__cell--non-numeric"><b>Twitter</b></td>  
>                <td class="mdl-data-table__cell--non-numeric">
>                  <a
> href="https://twitter.com/{{twitter}}">{{twitter}}</a></td>
>              </tr>
> {{/twitter}}' asMustacheTemplate value: { #twitter -> nil   } asDictionary
>
> gives empty string in my case.
>
> Norbert
>  
>> Am 29.05.2017 um 16:20 schrieb Norbert Hartl <[hidden email]>:
>>
>> Can you show some data you are injecting? It should work as you expect it.
>>
>> Norbert
>>
>>> Am 29.05.2017 um 15:26 schrieb Offray Vladimir Luna Cárdenas <[hidden email]>:
>>>
>>> Hi,
>>>
>>> I'm using Mustache for a project to build a dynamic distributed web site
>>> generator for public & open data, backed by Fossil and using Material
>>> Design Lite. I have a template like this:
>>>
>>> ========
>>>
>>> {{#twitter}}
>>>             <tr>
>>>               <td
>>> class="mdl-data-table__cell--non-numeric"><b>Twitter</b></td>  
>>>               <td class="mdl-data-table__cell--non-numeric">
>>>                 <a
>>> href="https://twitter.com/{{twitter}}">{{twitter}}</a></td>
>>>             </tr>
>>> {{/twitter}}
>>>
>>> ========
>>>
>>> that is mean to show or hide a row in a table, depending on if Twitter
>>> data for a profile is found in a user profile. When the profile doesn't
>>> have twitter data, the row is hidden, as supposed, and when it has, the
>>> row is shown, but without any actual twitter data. What I'm missing?
>>> Should I use partials in this case and how?
>>>
>>> Thanks,
>>>
>>> Offray
>>>
>>>
>>>
>>
>
>



Reply | Threaded
Open this post in threaded view
|

Re: Mustache: Making a conditional section show its values.

NorbertHartl
Offray,

I think I didn't get what you want at first. When using a section in mustache {{#twitter}} then the object value of the key twitter becomes the current context. Every property is resolved relative to this current context. If you want to use the current context itself as value you can use the dot notation {{ . }}. There was a problem when this context itself is a string. I solved that a year ago but I've seen that the newest configuration was not in the MetaRepo. It means if you loaded mustache from the catalog then you loaded a slightly older version that doesn't include that fix. I've update all MetaRepos from pharo4 to pharo6 for the newest configuration. If you load it now it should work.

hope that helps,

Norbert
 

> Am 29.05.2017 um 17:15 schrieb Offray Vladimir Luna Cárdenas <[hidden email]>:
>
> Yes I can share the data. Please load Brea project from [1] and do:
>
> =========
>
> | testUser  |
> testUser := BreaMember new createTestUser.
> testUser html
>
> =========
>
> [1] http://smalltalkhub.com/#!/~Offray/Brea
>
>
> You will see that the twitter portion of the row is showed, but without
> any actual data inside. You can also try this:
>
> =========
> '{{#twitter}}
>             <tr>
>               <td
> class="mdl-data-table__cell--non-numeric"><b>Twitter</b></td>  
>               <td class="mdl-data-table__cell--non-numeric">
>                 <a
> href="https://twitter.com/{{twitter}}">{{twitter}}</a></td>
>             </tr>
> {{/twitter}}' asMustacheTemplate value: { #twitter -> '@offrayLC'   }
> asDictionary
> =========
>
> with the same behavior.
>
> I think that the proper output will be the row showed with the data
> inside filled.
>
> Let me know how can I help to debug this.
>
> Thanks,
>
> Offray
>
> On 29/05/17 09:26, Norbert Hartl wrote:
>> To clarify. If the object you inject has a value which either does not contain the key twitter or it does container the key twitter but its value is nil then the section won't be shown.
>>
>> '{{#twitter}}
>>             <tr>
>>               <td
>> class="mdl-data-table__cell--non-numeric"><b>Twitter</b></td>  
>>               <td class="mdl-data-table__cell--non-numeric">
>>                 <a
>> href="https://twitter.com/{{twitter}}">{{twitter}}</a></td>
>>             </tr>
>> {{/twitter}}' asMustacheTemplate value: { #twitter -> nil   } asDictionary
>>
>> gives empty string in my case.
>>
>> Norbert
>>
>>> Am 29.05.2017 um 16:20 schrieb Norbert Hartl <[hidden email]>:
>>>
>>> Can you show some data you are injecting? It should work as you expect it.
>>>
>>> Norbert
>>>
>>>> Am 29.05.2017 um 15:26 schrieb Offray Vladimir Luna Cárdenas <[hidden email]>:
>>>>
>>>> Hi,
>>>>
>>>> I'm using Mustache for a project to build a dynamic distributed web site
>>>> generator for public & open data, backed by Fossil and using Material
>>>> Design Lite. I have a template like this:
>>>>
>>>> ========
>>>>
>>>> {{#twitter}}
>>>>            <tr>
>>>>              <td
>>>> class="mdl-data-table__cell--non-numeric"><b>Twitter</b></td>  
>>>>              <td class="mdl-data-table__cell--non-numeric">
>>>>                <a
>>>> href="https://twitter.com/{{twitter}}">{{twitter}}</a></td>
>>>>            </tr>
>>>> {{/twitter}}
>>>>
>>>> ========
>>>>
>>>> that is mean to show or hide a row in a table, depending on if Twitter
>>>> data for a profile is found in a user profile. When the profile doesn't
>>>> have twitter data, the row is hidden, as supposed, and when it has, the
>>>> row is shown, but without any actual twitter data. What I'm missing?
>>>> Should I use partials in this case and how?
>>>>
>>>> Thanks,
>>>>
>>>> Offray
>>>>
>>>>
>>>>
>>>
>>
>>
>
>
>


Reply | Threaded
Open this post in threaded view
|

Re: Mustache: Making a conditional section show its values.

Offray Vladimir Luna Cárdenas-2
Norbert,

Dot notation solves the issue and [1] works as expected.

=[1]========

'{{#twitter}}
  <tr>
    <td class="mdl-data-table__cell--non-numeric">
      <b>Twitter</b></td>  
    <td class="mdl-data-table__cell--non-numeric">
      <a href="https://twitter.com/{{.}}">
        {{.}}</a></td>
  </tr>
{{/twitter}}' asMustacheTemplate value: { #twitter -> '@offrayLC'   }
asDictionary

===========

Thanks for the work on Mustache and the Enterprise Pharo chapter. Is a
really good written book (so far I have read the Mustache, Teapot and
ZnServer chapters). I wonder if there is a place for extensions and
clarifications of this book in its online version, for example,
regarding dot notation.

Cheers,

Offray

On 29/05/17 16:48, Norbert Hartl wrote:

> Offray,
>
> I think I didn't get what you want at first. When using a section in mustache {{#twitter}} then the object value of the key twitter becomes the current context. Every property is resolved relative to this current context. If you want to use the current context itself as value you can use the dot notation {{ . }}. There was a problem when this context itself is a string. I solved that a year ago but I've seen that the newest configuration was not in the MetaRepo. It means if you loaded mustache from the catalog then you loaded a slightly older version that doesn't include that fix. I've update all MetaRepos from pharo4 to pharo6 for the newest configuration. If you load it now it should work.
>
> hope that helps,
>
> Norbert
>  
>> Am 29.05.2017 um 17:15 schrieb Offray Vladimir Luna Cárdenas <[hidden email]>:
>>
>> Yes I can share the data. Please load Brea project from [1] and do:
>>
>> =========
>>
>> | testUser  |
>> testUser := BreaMember new createTestUser.
>> testUser html
>>
>> =========
>>
>> [1] http://smalltalkhub.com/#!/~Offray/Brea
>>
>>
>> You will see that the twitter portion of the row is showed, but without
>> any actual data inside. You can also try this:
>>
>> =========
>> '{{#twitter}}
>>             <tr>
>>               <td
>> class="mdl-data-table__cell--non-numeric"><b>Twitter</b></td>  
>>               <td class="mdl-data-table__cell--non-numeric">
>>                 <a
>> href="https://twitter.com/{{twitter}}">{{twitter}}</a></td>
>>             </tr>
>> {{/twitter}}' asMustacheTemplate value: { #twitter -> '@offrayLC'   }
>> asDictionary
>> =========
>>
>> with the same behavior.
>>
>> I think that the proper output will be the row showed with the data
>> inside filled.
>>
>> Let me know how can I help to debug this.
>>
>> Thanks,
>>
>> Offray
>>
>> On 29/05/17 09:26, Norbert Hartl wrote:
>>> To clarify. If the object you inject has a value which either does not contain the key twitter or it does container the key twitter but its value is nil then the section won't be shown.
>>>
>>> '{{#twitter}}
>>>             <tr>
>>>               <td
>>> class="mdl-data-table__cell--non-numeric"><b>Twitter</b></td>  
>>>               <td class="mdl-data-table__cell--non-numeric">
>>>                 <a
>>> href="https://twitter.com/{{twitter}}">{{twitter}}</a></td>
>>>             </tr>
>>> {{/twitter}}' asMustacheTemplate value: { #twitter -> nil   } asDictionary
>>>
>>> gives empty string in my case.
>>>
>>> Norbert
>>>
>>>> Am 29.05.2017 um 16:20 schrieb Norbert Hartl <[hidden email]>:
>>>>
>>>> Can you show some data you are injecting? It should work as you expect it.
>>>>
>>>> Norbert
>>>>
>>>>> Am 29.05.2017 um 15:26 schrieb Offray Vladimir Luna Cárdenas <[hidden email]>:
>>>>>
>>>>> Hi,
>>>>>
>>>>> I'm using Mustache for a project to build a dynamic distributed web site
>>>>> generator for public & open data, backed by Fossil and using Material
>>>>> Design Lite. I have a template like this:
>>>>>
>>>>> ========
>>>>>
>>>>> {{#twitter}}
>>>>>            <tr>
>>>>>              <td
>>>>> class="mdl-data-table__cell--non-numeric"><b>Twitter</b></td>  
>>>>>              <td class="mdl-data-table__cell--non-numeric">
>>>>>                <a
>>>>> href="https://twitter.com/{{twitter}}">{{twitter}}</a></td>
>>>>>            </tr>
>>>>> {{/twitter}}
>>>>>
>>>>> ========
>>>>>
>>>>> that is mean to show or hide a row in a table, depending on if Twitter
>>>>> data for a profile is found in a user profile. When the profile doesn't
>>>>> have twitter data, the row is hidden, as supposed, and when it has, the
>>>>> row is shown, but without any actual twitter data. What I'm missing?
>>>>> Should I use partials in this case and how?
>>>>>
>>>>> Thanks,
>>>>>
>>>>> Offray
>>>>>
>>>>>
>>>>>
>>>
>>
>>
>
>


Reply | Threaded
Open this post in threaded view
|

Re: Mustache: Making a conditional section show its values.

NorbertHartl
Offray,

> Am 30.05.2017 um 02:45 schrieb Offray Vladimir Luna Cárdenas <[hidden email]>:
>
> Norbert,
>
> Dot notation solves the issue and [1] works as expected.
>
> =[1]========
>
> '{{#twitter}}
>  <tr>
>    <td class="mdl-data-table__cell--non-numeric">
>      <b>Twitter</b></td>  
>    <td class="mdl-data-table__cell--non-numeric">
>      <a href="https://twitter.com/{{.}}">
>        {{.}}</a></td>
>  </tr>
> {{/twitter}}' asMustacheTemplate value: { #twitter -> '@offrayLC'   }
> asDictionary
>
> ===========
>
> Thanks for the work on Mustache and the Enterprise Pharo chapter. Is a
> really good written book (so far I have read the Mustache, Teapot and
> ZnServer chapters). I wonder if there is a place for extensions and
> clarifications of this book in its online version, for example,
> regarding dot notation.
>
the credits for the enterprise chapter go to Stef. He does the annoying task of collecting information and make them publishable.
The book is supposed to be a community effort. So if you have something to add I think pull requests are highly welcomed. And the dot notation is good thing to add 😉You can just add a few sentences...

glad it works for you,

Norbert

> Cheers,
>
> Offray
>
>> On 29/05/17 16:48, Norbert Hartl wrote:
>> Offray,
>>
>> I think I didn't get what you want at first. When using a section in mustache {{#twitter}} then the object value of the key twitter becomes the current context. Every property is resolved relative to this current context. If you want to use the current context itself as value you can use the dot notation {{ . }}. There was a problem when this context itself is a string. I solved that a year ago but I've seen that the newest configuration was not in the MetaRepo. It means if you loaded mustache from the catalog then you loaded a slightly older version that doesn't include that fix. I've update all MetaRepos from pharo4 to pharo6 for the newest configuration. If you load it now it should work.
>>
>> hope that helps,
>>
>> Norbert
>>
>>> Am 29.05.2017 um 17:15 schrieb Offray Vladimir Luna Cárdenas <[hidden email]>:
>>>
>>> Yes I can share the data. Please load Brea project from [1] and do:
>>>
>>> =========
>>>
>>> | testUser  |
>>> testUser := BreaMember new createTestUser.
>>> testUser html
>>>
>>> =========
>>>
>>> [1] http://smalltalkhub.com/#!/~Offray/Brea
>>>
>>>
>>> You will see that the twitter portion of the row is showed, but without
>>> any actual data inside. You can also try this:
>>>
>>> =========
>>> '{{#twitter}}
>>>            <tr>
>>>              <td
>>> class="mdl-data-table__cell--non-numeric"><b>Twitter</b></td>  
>>>              <td class="mdl-data-table__cell--non-numeric">
>>>                <a
>>> href="https://twitter.com/{{twitter}}">{{twitter}}</a></td>
>>>            </tr>
>>> {{/twitter}}' asMustacheTemplate value: { #twitter -> '@offrayLC'   }
>>> asDictionary
>>> =========
>>>
>>> with the same behavior.
>>>
>>> I think that the proper output will be the row showed with the data
>>> inside filled.
>>>
>>> Let me know how can I help to debug this.
>>>
>>> Thanks,
>>>
>>> Offray
>>>
>>>> On 29/05/17 09:26, Norbert Hartl wrote:
>>>> To clarify. If the object you inject has a value which either does not contain the key twitter or it does container the key twitter but its value is nil then the section won't be shown.
>>>>
>>>> '{{#twitter}}
>>>>            <tr>
>>>>              <td
>>>> class="mdl-data-table__cell--non-numeric"><b>Twitter</b></td>  
>>>>              <td class="mdl-data-table__cell--non-numeric">
>>>>                <a
>>>> href="https://twitter.com/{{twitter}}">{{twitter}}</a></td>
>>>>            </tr>
>>>> {{/twitter}}' asMustacheTemplate value: { #twitter -> nil   } asDictionary
>>>>
>>>> gives empty string in my case.
>>>>
>>>> Norbert
>>>>
>>>>> Am 29.05.2017 um 16:20 schrieb Norbert Hartl <[hidden email]>:
>>>>>
>>>>> Can you show some data you are injecting? It should work as you expect it.
>>>>>
>>>>> Norbert
>>>>>
>>>>>> Am 29.05.2017 um 15:26 schrieb Offray Vladimir Luna Cárdenas <[hidden email]>:
>>>>>>
>>>>>> Hi,
>>>>>>
>>>>>> I'm using Mustache for a project to build a dynamic distributed web site
>>>>>> generator for public & open data, backed by Fossil and using Material
>>>>>> Design Lite. I have a template like this:
>>>>>>
>>>>>> ========
>>>>>>
>>>>>> {{#twitter}}
>>>>>>           <tr>
>>>>>>             <td
>>>>>> class="mdl-data-table__cell--non-numeric"><b>Twitter</b></td>  
>>>>>>             <td class="mdl-data-table__cell--non-numeric">
>>>>>>               <a
>>>>>> href="https://twitter.com/{{twitter}}">{{twitter}}</a></td>
>>>>>>           </tr>
>>>>>> {{/twitter}}
>>>>>>
>>>>>> ========
>>>>>>
>>>>>> that is mean to show or hide a row in a table, depending on if Twitter
>>>>>> data for a profile is found in a user profile. When the profile doesn't
>>>>>> have twitter data, the row is hidden, as supposed, and when it has, the
>>>>>> row is shown, but without any actual twitter data. What I'm missing?
>>>>>> Should I use partials in this case and how?
>>>>>>
>>>>>> Thanks,
>>>>>>
>>>>>> Offray
>>>>>>
>>>>>>
>>>>>>
>>>>
>>>
>>>
>>
>>
>
>


Reply | Threaded
Open this post in threaded view
|

Re: Mustache: Making a conditional section show its values.

Offray Vladimir Luna Cárdenas-2


On 30/05/17 02:25, Norbert Hartl wrote:
> the credits for the enterprise chapter go to Stef. He does the annoying task of collecting information and make them publishable.
> The book is supposed to be a community effort. So if you have something to add I think pull requests are highly welcomed. And the dot notation is good thing to add 😉You can just add a few sentences...
>
> glad it works for you,

Yes. Steph is some kind of machine. Maybe he has secretly made some
Pharo bots to outsource parts of his brain, and do everything that he is
doing. I will add the dot notation via pull request. I think that the
proper place would be on the Partials part, that is dealing with
template reusing (Something like titled "Templates reuse: Dot notation &
Partials".

Cheers,

Offray




Reply | Threaded
Open this post in threaded view
|

Re: Mustache: Making a conditional section show its values.

Offray Vladimir Luna Cárdenas-2
Done. New proposal for dot notation:

https://github.com/SquareBracketAssociates/EnterprisePharo/compare/master...offray:patch-1

My two pesos.

Cheers,

Offray


On 30/05/17 09:33, Offray Vladimir Luna Cárdenas wrote:

>
> On 30/05/17 02:25, Norbert Hartl wrote:
>> the credits for the enterprise chapter go to Stef. He does the annoying task of collecting information and make them publishable.
>> The book is supposed to be a community effort. So if you have something to add I think pull requests are highly welcomed. And the dot notation is good thing to add 😉You can just add a few sentences...
>>
>> glad it works for you,
> Yes. Steph is some kind of machine. Maybe he has secretly made some
> Pharo bots to outsource parts of his brain, and do everything that he is
> doing. I will add the dot notation via pull request. I think that the
> proper place would be on the Partials part, that is dealing with
> template reusing (Something like titled "Templates reuse: Dot notation &
> Partials".
>
> Cheers,
>
> Offray
>
>
>
>
>