templating-engine

How to indent content of included template

别来无恙 提交于 2019-12-02 00:54:36
I am using go templates to create yaml definitions for kubernetes. I am trying to nest templates but run into issues where I can't re-use a definition simply because the indention is wrong when included. I.e., in one case the contents need indentation but do not in another. How can I control the indention of included content? Example below. I am reusing pod.tmpl, in the first case it can be included as is. In the second case I need to indent the entire contents so it becomes member of service {{ if (eq .Case "pod") # NO indenting {{ template "pod" }} {{ end }} {{ if (eq .Case "service")

Creating a simple but flexible templating engine

时光总嘲笑我的痴心妄想 提交于 2019-12-01 11:14:47
I am trying to build a basic templating engine. Like the template engines already available as open source, I am using search and replace techniques. However, as the search and replace have to be hardcoded, it is not so much flexible. What I mean to say is, as an example, I am using something like this $templateMarkup = '<div class="title">{_TITLE_}</div>'; $renderedMarkup = str_replace("{_TITLE_}",$title,$templateMarkup); echo $renderedMarkup; As you can see, it is hardcoded. So I have to purposely know all the placeholders to accomplish a successful render. I am a little bit weak in regular

Creating a simple but flexible templating engine

被刻印的时光 ゝ 提交于 2019-12-01 07:41:28
问题 I am trying to build a basic templating engine. Like the template engines already available as open source, I am using search and replace techniques. However, as the search and replace have to be hardcoded, it is not so much flexible. What I mean to say is, as an example, I am using something like this $templateMarkup = '<div class="title">{_TITLE_}</div>'; $renderedMarkup = str_replace("{_TITLE_}",$title,$templateMarkup); echo $renderedMarkup; As you can see, it is hardcoded. So I have to

Pass JavaScript object/hash to Handlebars helper?

房东的猫 提交于 2019-11-30 12:33:13
Is it possible to pass a JavaScript object/hash into a Handlebars helper call? I'd like to do something like this: <label>Label here</label> {{#textField {'id':'text_field_1', 'class':'some-class', size:30} }}{{/textField}} <p>Help text here.</p> Here is a jsFiddle . Currently it produces the following error Uncaught Error: Parse error on line 3: ...bel> {{#textField {'id':'text_field_1' ----------------------^ Expecting 'CLOSE', 'CLOSE_UNESCAPED', 'STRING', 'INTEGER', 'BOOLEAN', 'ID', 'DATA', 'SEP', got 'INVALID' Alternatively I could probably do this and split on ',', but I am not fond of

Pass JavaScript object/hash to Handlebars helper?

社会主义新天地 提交于 2019-11-29 17:37:34
问题 Is it possible to pass a JavaScript object/hash into a Handlebars helper call? I'd like to do something like this: <label>Label here</label> {{#textField {'id':'text_field_1', 'class':'some-class', size:30} }}{{/textField}} <p>Help text here.</p> Here is a jsFiddle. Currently it produces the following error Uncaught Error: Parse error on line 3: ...bel> {{#textField {'id':'text_field_1' ----------------------^ Expecting 'CLOSE', 'CLOSE_UNESCAPED', 'STRING', 'INTEGER', 'BOOLEAN', 'ID', 'DATA',

What are the differences between Mustache.js and Handlebars.js?

白昼怎懂夜的黑 提交于 2019-11-27 09:57:29
Major differences I've seen are: Handlebars adds #if , #unless , #with , and #each Handlebars adds helpers Handlebars templates are compiled (Mustache can be too) Handlebars supports paths Allows use of {{this}} in blocks (which outputs the current item's string value) Handlebars.SafeString() (and maybe some other methods) Handlebars is 2 to 7 times faster Mustache supports inverted sections (i.e. if !x ... ) (Please correct me if I'm wrong with the above.) Are there any other major differences I am missing? frontendbeauty You've pretty much nailed it, however Mustache templates can also be

Can you recommend a .net template engine? [closed]

白昼怎懂夜的黑 提交于 2019-11-26 15:48:12
I am looking for a .net templating engine - something simple, lightweight, stable with not too many dependencies. All I need it for at the moment is creating templated plain text and html emails. Can anyone give me a good recommendation? If it helps at all - something like Java's Freemarker or Velocity libraries. [UPDATE] Thanks for the answers so far - much appreciated. I am really intested in recommendations or war stories from when you have used these libraries. Seems to be the best way to make a decision without trying each in turn. Here's a couple more: NHaml Spark Brail (can be used

What are the differences between Mustache.js and Handlebars.js?

╄→尐↘猪︶ㄣ 提交于 2019-11-26 14:58:31
问题 Major differences I've seen are: Handlebars adds #if , #unless , #with , and #each Handlebars adds helpers Handlebars templates are compiled (Mustache can be too) Handlebars supports paths Allows use of {{this}} in blocks (which outputs the current item's string value) Handlebars.SafeString() (and maybe some other methods) Handlebars is 2 to 7 times faster Mustache supports inverted sections (i.e. if !x ... ) (Please correct me if I'm wrong with the above.) Are there any other major

Can you recommend a .net template engine? [closed]

血红的双手。 提交于 2019-11-26 04:38:28
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 8 months ago . I am looking for a .net templating engine - something simple, lightweight, stable with not too many dependencies. All I need it for at the moment is creating templated plain text and html emails. Can anyone give me a good recommendation? If it helps at all - something like Java\'s Freemarker or Velocity