Reputation: 967
Using mustache.js on a Jekyll site, is it possible to use a mustache variable within a liquid code block?
Something like:
{% if liquidVar == {% raw %}{{ mustacheVar }}{% endraw %} %}
// do something
{% endif %}
Upvotes: 0
Views: 723
Reputation: 341
The example you provided doesn't make logical sense. The liquid {% if %}
will be processed only during build, a runtime javascript variable won't be available then.
That aside, if you are using mustache.js with Jekyll you will want to change the mustasche delimiters.
See https://github.com/janl/mustache.js/#custom-delimiters
Your best bet is to override it globally. This will let you avoid having to pollute your code with {% raw %}
blocks everywhere. The following will let you use {| variable-name |}
for mustache variables
Mustache.tags = [ '{|', '|}' ];
It is possible to override it at a template level, but there you will need to escape it
{% raw %}{{={| |}=}}{% endraw %}
Upvotes: 1