Ember 1.11.0-beta "A block can only be used inside an HTML element or another block"

I am trying to download some remote templates using 1.11 beta 4 and I got confused by the error when the ember-template compiler tried to compile the template. It throws out "A block that can only be used to exclude an HTML element or another block." I am compiling a template with:

var compiledTemplate = Ember.Handlebars.compile(templateText);

Has anyone seen this before? Template:

<p{{#id}} id="{{id}}"{{/id}} data-name="{{name}}" class="flag {{#alert}}{{type}} {{type}}-input{{/alert}} {{styleClass}}{{^alert}} hide{{/alert}}">
  <span{{#id}} id="{{alertSevId}}"{{/id}} class="alertSeverity icon">
    {{#alert}}{{type}}{{/alert}}
  </span>
  <span{{#id}} id="{{alertMsgId}}"{{/id}} class="alertMessage">
    {{#alert}}{{message}}{{/alert}}
  </span>
</p>
+4
source share
3 answers

I am studying Ember and today I am stuck in the same error message, "Error: A block may only be used inside an HTML element or another block."

I am using Ember v1.10, however.

I worked on a tutorial and commented on part of my HTML so that I could try something else:

<script type="text/x-handlebars" data-template-name="logs">
    <section>
        <ul>
            {{#each log in model}}
            <li>{{log.name}}</li>
            {{/each}}
        </ul>

       <!--<ul>-->
       <!--{{#each dev in controller}}-->
       <!--<li>{{dev}}</li>-->
       <!--{{/each}}-->
       <!--</ul>-->
       <!--<button {{action "clickMe"}}Click me!</button>-->
       <!--<p>{{renderedOn}}</p>-->
    </section>
</script>

, . , - , , , JavaScript, HTML. , , .

, :

  • ,
  • ,

, , :

   <!--{{#each dev in controller}}-->
   <!--{{/each}}-->

, , , , , .

+6

"", "#" . . "#" {{#id ...}}

+3

It seems you want to conditionally set the html attribute, if one is defined. To do this, you can translate this mustache: <div {{#id}}id="{{id}}" {{/id}}> ... into this Ember hbs template (note the lack of citations around {{id}}): <div id={{id}}> You will achieve the same result: id was set - <div id="foo"> id was not set - <div > Avoid this unwanted result -<div id="">

+1
source

All Articles