[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.javascript

how to change a mustache script

jrough

11/25/2014 6:10:00 PM

I need to change the mustache code. Basically if a web page is on a certain tab then it adds the class="current" to the <li>. I need it to skip one tab call activity-tab. How would I do this?
<ul>
{{# each tab}}
<li class="{{#if isCurrent}}current{{/if}}" id="{{id}}" test-event="{{id}}" tabindex="1">
<h4 >{{name}}</h4>
</li>
{{/each}}

---------------------------Something like---------------

{{# each tab}}
<li class="{{#if isCurrent && !== "activity-tab"}}current{{/if}}" id="{{id}}" test-event="{{id}}" tabindex="1">
<h4 >{{name}}</h4>
</li>
{{/each}}

thanks,
3 Answers

Chris Riesbeck

11/25/2014 6:36:00 PM

0

On 11/25/2014 12:10 PM, JRough wrote:
> I need to change the mustache code. Basically if a web page is on a certain tab then it adds the class="current" to the <li>. I need it to skip one tab call activity-tab. How would I do this?
> <ul>
> {{# each tab}}
> <li class="{{#if isCurrent}}current{{/if}}" id="{{id}}" test-event="{{id}}" tabindex="1">
> <h4 >{{name}}</h4>
> </li>
> {{/each}}
>
> ---------------------------Something like---------------
>
> {{# each tab}}
> <li class="{{#if isCurrent && !== "activity-tab"}}current{{/if}}" id="{{id}}" test-event="{{id}}" tabindex="1">
> <h4 >{{name}}</h4>
> </li>
> {{/each}}
>
> thanks,
>
Mustache tries to be as logic-less as possible, to keep the HTML
uncluttered. The logic should be in the JavaScript that creates the data
you feed to Mustache. Change your JavaScript to create a data model that
has the desired class for each tab in it, then in the template, just
iterate over the tabs and insert the class.

jrough

11/25/2014 7:04:00 PM

0

On Tuesday, November 25, 2014 10:35:33 AM UTC-8, Chris Riesbeck wrote:
> On 11/25/2014 12:10 PM, JRough wrote:
> > I need to change the mustache code. Basically if a web page is on a certain tab then it adds the class="current" to the <li>. I need it to skip one tab call activity-tab. How would I do this?
> > <ul>
> > {{# each tab}}
> > <li class="{{#if isCurrent}}current{{/if}}" id="{{id}}" test-event="{{id}}" tabindex="1">
> > <h4 >{{name}}</h4>
> > </li>
> > {{/each}}
> >
> > ---------------------------Something like---------------
> >
> > {{# each tab}}
> > <li class="{{#if isCurrent && !== "activity-tab"}}current{{/if}}" id="{{id}}" test-event="{{id}}" tabindex="1">
> > <h4 >{{name}}</h4>
> > </li>
> > {{/each}}
> >
> > thanks,
> >
> Mustache tries to be as logic-less as possible, to keep the HTML
> uncluttered. The logic should be in the JavaScript that creates the data
> you feed to Mustache. Change your JavaScript to create a data model that
> has the desired class for each tab in it, then in the template, just
> iterate over the tabs and insert the class.

I can't change the data model because I need the tab on the page otherwise I don't have a page but on that page I don't want the list. Isn't there a helper function?

Thomas 'PointedEars' Lahn

11/25/2014 10:09:00 PM

0

JRough wrote:

> I need to change the mustache code.

How did you get the idea that this would be on-topic here?

> [Google Groups-created code soup]

Please read the FAQ.

> <li class="{{#if isCurrent && !== "activity-tab"}}current{{/if}}"
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
If your posting is remotely on-topic here, that line contains a syntax
error.

--
PointedEars
FAQ: <http://PointedEars.... | SVN: <http://PointedEars.de...
Twitter: @PointedEars2 | ES Matrix: <http://PointedEars.de/es-...
Please do not cc me. / Bitte keine Kopien per E-Mail.