blaze icon indicating copy to clipboard operation
blaze copied to clipboard

Be able to have more contentBlock in template

Open DblK opened this issue 2 years ago • 1 comments

Hi,

I have the following usecase :

<template name="Component>
  <div class="head">
    {{> Template.contentBlock}}
  </div>
  <div class="content">
    {{> Template.elseBlock}}
  </div>
</template>

So now I can call the template like this:

{{#Component}}
  Part Head
{{else}}
  Part Content
{{/Component}}

So it's fine even if it's look "hacky" to use else block to provide two contentBlock. In case I built something with more than two I can not use this trick.

I wish to be able to define multiple contentBlock in template and to call be able to specific which content for which contentBlock.

Example usage :

{{#Component}}
<templateBlock1>
  Part Head
</templateBlock1>
<templateBlock2>
  Part Content
</templateBlock2>
{{/Component}}

and for the definion:
```hbs
<template name="Component>
  <div class="head">
    {{> Template.contentBlock1}}
  </div>
  <div class="content">
    {{> Template.contentBlock2}}
  </div>
</template>

It should be like extending the Template.elseBlock to allow more than one. The goal is to be able to build more flexible template.

DblK avatar Jan 28 '23 13:01 DblK

The elseBlock is actually just undocumented but it's 100% supported. However, I agree that there could be a better solution for multiple content blocks. Currently we can pass arguments to the contentblock, so we could structure them using something like a reserved ìd` attribute:

<template name="component">
  <hr>
  {{> Template.contentBlock id="foo"}}
  <hr>
  {{> Template.contentBlock id="bar"}}
</template>

we could use this attribute to inject a view, say contentBlock, that could be used within the parent:

{{#component}}
  {{#this.contentBlock id="foo"}}
    bar
  {{/this.contentBlock}}
  {{#this.contentBlock id="bar"}}
      moo
  {{/this.contentBlock}}
{{/component}}

Alternatively instead of using ids we could also see if it's feasible to simply use index-based order but that would require to always call all this.contentBlock while the id based solution would allow to skip certain blocks, if desired, which would be the most flexible soltion IMO.

jankapunkt avatar Feb 28 '23 07:02 jankapunkt