1

I have this template code:

{{#priceList}}
  {{#last}}
    <strong>{{currency}}</strong>
  {{/last}}
  {{^last}}
    <del>{{currency}}</del>
  {{/last}}
{{/finalPriceList}}

and I'm trying to go through this data:

priceList: [
  { price: 50, currency: '$50.00', last: false },
  { price: 25, currency: '$25.00', last: true }
]

All I want to do is output:

<del>$50.00</del> <strong>$25.00</strong>

Am I approaching this right? I've tried last as undefined instead of false as well.

My code outputs

<del>$50.00</del> {{/last}} <strong>$25.00</strong> <del>$25.00</strong> {{/last}}

1 Answer 1

3

Your template was incorrect - had {{/finalPriceList}}, should have been {{/priceList}}, i.e.:

{{#priceList}}
  {{#last}}
    <strong>{{currency}}</strong>
  {{/last}}
  {{^last}}
    <del>{{currency}}</del>
  {{/last}}
{{/priceList}}

See a working example here:

Sign up to request clarification or add additional context in comments.

4 Comments

Oddly enough I had that right in the code and it was still giving me the error. I switched the {{^}} and {{#}} position and it outputs fine. It must be something sooner in my template that causes it? Either way. Thank you very much! It's good to know I was actually doing it right.
Hm, strange... How are you loading the file - check the jsFiddle example I gave and see if there's anything different in your code. If you are building it as a string, you need `` as the last character to have it continue lines. You should probably use Firebug or something like that to see if you get any error messages - that would help greatly pinpointing the issue.
I feel like an absolute crazy person but it's working the other way now as well. I am using jQuery to get the template code, just Mustache.to_html( $('.product.template').html(), product ); When it wasn't working I wasn't getting any error messages. Feel free to ignore me now. Thank you again. =)
Cool, glad you got it sorted out!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.