canjs / can-stache

Live binding handlebars templates
https://canjs.com/doc/can-stache.html
MIT License
10 stars 13 forks source link

Suggest using partials when stache auto-closes elements #713

Open phillipskevin opened 5 years ago

phillipskevin commented 5 years ago

From https://bitovi-community.slack.com/archives/CFC22NZ8A/p1565274636104700.

Stache will automatically close elements when trying to wrap an opening or closing tag (see "The following sections are not supported" in https://canjs.com/doc/can-stache.html#Magictags).

This means that if you do something like:

{{#if(vertical)}}
<div class='row'>
    <div class='col-3'>
{{/if}}

<p>some other content</p>

{{#if(vertical)}}
    </div>
</div>
{{/if}}

...stache will convert it to

<div class='row'>
    <div class='col-3'></div>
</div>

<p>some other content</p>

We give a warning for this:

unexpected closing tag

expected

We should suggest using partials to handle this

{{<thestuff}}
    <p>some other content</p>
{{/thestuff}}

{{#if(vertical)}}
<div class='row'>
    <div class='col-3'>
        {{thestuff()}}
    </div>
</div>
{{else}}
{{thestuff()}}
{{/if}}

We should put a section in the docs for this and possible add a link to it from the warning (although it might be hard to determine when someone is doing this on purpose vs when it was a mistake).