question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Browser does not respect template markup

See original GitHub issue

See https://jsfiddle.net/8vfesbgf/1/

<div id="alltemplates" class="hidden">
<code id="tpl_fieldtype">
    <div class="form-group">
        <label>{{:fieldname}}</label>
        <select class="fieldtype form-control" data-name="{{:fieldname}}">
            {{for allfieldtypes}}
            <option value="{{:ftype}}" {{ if ftype == fieldtype }}selected{{/if}}>{{:ftype}}</option>
            {{/for}}
        </select>
    </div>
</code>
</div>

See 3 commented blocks in the fiddle - nothing of these returns correct content. It seems browser does not process this block as is. I see it as:

 {{for allfieldtypes}}
    <option if}}="" }}selected{{="" fieldtype="" ftype="=" if="" {{="" value="{{:ftype}}">{{:ftype}} </option>
{{/for}} 

How do I render this template?

Ubuntu 15.10: Firefox 46.0.1 / Chromium 50.0.2661.102

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
Paul-Martincommented, May 27, 2016

If you are doing this in a browser then your template should be in a script tag. And then you need to call render and insert the resulting string in to the dom.

JSRender does not somehow make the browser dom understand it’s {{tag}} notation. You place the template in script tag so that the browser will ignore it. Then you use javascript to render the template and insert it into the dom where you would like.

<script id='helloworld' type='text/x-jsrender'> <span>{{>hello }}</span> </script>

var model = { hello: ‘world’ };

var rendered = $.template(‘#helloworld’).render(model);

$(‘body’).html(rendered);

On May 27, 2016, at 11:55 AM, Alexey Kolyanov notifications@github.com wrote:

Really? Have you ever tried to do this in jsfiddle? I get these lines:

            <option value="ft1" {{="" if="" ftype="=" fieldtype="" }}selected{{="" if}}="">ft1</option>

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

1reaction
grma1commented, May 27, 2016

the main problem was, that the code block is parsed by the html engine.

try the following:

<div id="alltemplates" class="hidden">
    <script type="text/x-jsrender" id="tpl_fieldtype">
        <div class="form-group">
            <label>{{:fieldname}}</label>
            <select class="fieldtype form-control" data-name="{{:fieldname}}">
                {{for allfieldtypes}}
                <option value="{{:ftype}}" {{if ftype === fieldtype}}selected{{/if}}>{{:ftype}}</option>
                {{/for}}
            </select>
        </div>
    </script>
</div>
Read more comments on GitHub >

github_iconTop Results From Across the Web

I am trying to debug the markup of my email templates. I ...
I created an html template with NO colors specified (font or background), ... suddenly dark mode is not respected and it appears that...
Read more >
<pre>: The Preformatted Text element - HTML - MDN Web Docs
The HTML element represents preformatted text which is to be presented exactly as written in the HTML file. The text is typically rendered ......
Read more >
Why does HTML require that multiple spaces show up as a ...
Spaces are compacted in HTML because there's a distinction between how HTML is formatted and how it should be rendered. Consider a page...
Read more >
&nbsp and HTML Space Challenges and Tricks | Mailtrap Blog
If you were to use either of the entities directly in the code, the browser would interpret them as HTML and render them...
Read more >
Customizing your templates for email notifications
Note: HTML template editing is not enabled by default for trials. ... the way HTML and CSS are rendered in different web browsers...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found