Skip to content

Add ternary and setVar operations#65

Open
Michael-Gannon wants to merge 2 commits intoelving:masterfrom
Michael-Gannon:master
Open

Add ternary and setVar operations#65
Michael-Gannon wants to merge 2 commits intoelving:masterfrom
Michael-Gannon:master

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