Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ternary and setVar operations #65

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Michael-Gannon
Copy link

Added:

ternary - a {{ternary true "was true" "was false"}} operator
setVar - enable setting new variables on the context {{setVar "newVar" "var value" this}}{newVar}}

Together I've found using these like has cleaned up code that looked like this:

<span>
{{#if useRemote }}
<a class="title" href="/items/remote-"{{id}}>the item name</span>
{{else}}
<a class="title" href="/items/local-"{{id}}>the item name</span>
{{/if}}
<span class="desc">some description</span>
{{#if useRemote }}
<a class="callToAction" href="/items/remote-"{{id}}/>buy me now</item>
{{else}}
<a class="callToAction" href="/items/local-"{{id}}/>buy me now</item>
{{/if}}
</span>

** obviously this could itself have been a helper that specifically generated id's but I found I was creating HEAPS of little helpers, this simplified my life

To this:

<span>
{{setVar "itemId" (ternary useRemote (concat "remote-" id) (concat "local-" id) ) }}
<a class="title" href="/items/"{{itemId}}>the item name</span>
<span class="desc">some description</span>
<a class="callToAction" href="/items/"{{itemId}}/>buy me now</item>
</span>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant