-
-
Save nathanpalmer/3707126 to your computer and use it in GitHub Desktop.
how "grips" templating handles it, in response to https://gist.github.com/3696453
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script id="template" type="text/x-jquery-tmpl"> | |
<h1>Settings</h1> | |
{{each(name,setting) settings}} | |
<h2>${name}</h2> | |
{{each(index,value) ['low','high']}} | |
<input type="radio" name="${name}" value="${value}" {{if setting === value}}checked{{/if}}> ${value} | |
{{/each}} | |
{{/each}} | |
</script> | |
<!-- | |
Here's how jQuery templating engine would handle it (yes I know it's been dead for some time.) | |
- I named each index/value in the loops for clarify | |
- otherwise I can reference $index or $value. However that gets difficult with two loops. | |
- I threw this in a script tag however this isn't how we normally use it (written in a separate file and the compiled down to javascript.) | |
- Used the if conditional for the checked tag | |
--> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
So, in the inner loop, when you do
${name}
, how would you have done that if you hadn't named your outer loop's$index
and$value
? Is there a special syntax for accessing the parent scope?If you look at how grips handles things, I think I agree a lot with this approach, except for the inline
if
construct. I really think conditional logic shouldn't be inline in the template, so grips lets you "pre-compute" your conditionals in the section/partial definition header.https://gist.github.com/3706912