posthtml / posthtml-extend

Template extending (Jade-like)
MIT License
46 stars 9 forks source link

Support for rendering multiple `<block>` tags with the same name #50

Closed nokazn closed 2 years ago

nokazn commented 2 years ago

Overview

Hi, there.

I encountered the similar issue with #47. I created content.html like below, but couldn't get expected result.

<!-- content.html -->
<extends src="layout.html">
    <fill name="content"><p>content</p></fill>
</extends>
<!-- layout.html -->
<div>
    <slot name="content"></slot>
    <slot name="content"></slot>
    <slot name="content"></slot>
</div>

Expected behavior

<div>
    <p>content</p>
    <p>content</p>
    <p>content</p>
</div>

Actual behavior

<div>
    <slot name="content"></slot>
    <slot name="content"></slot>
    <p>content</p>
</div>

This PR is a patch for this issue.

Changes

Related

thewebartisan7 commented 2 years ago

@nokazn the issue you mention was referring to this issue https://github.com/posthtml/posthtml-expressions/issues/126#issue-1125181767

It's a bit different, where you have multiple extends in one page and not multiple slots in one extends.

Or does this PR fix also the case above?

nokazn commented 2 years ago

@thewebartisan7 I think this PR fixes both where you have multiple extends in one page and multiple slots in one extends.

  1. multiple extends in one page https://github.com/posthtml/posthtml-extend/blob/ccf454a4b0ead941626bd7c09aae79c0e8c2388c/test/extend.js#L322-L368
  2. multiple slots in one extends https://github.com/posthtml/posthtml-extend/blob/ccf454a4b0ead941626bd7c09aae79c0e8c2388c/test/extend.js#L264-L290
thewebartisan7 commented 2 years ago

Thanks for your reply. My bad I didn't check test. I am glad to hear that it works now.

I was checking into posthtml-modules to allow multiple tag with "slot" like in posthtml-extend, as I thought extend was intended to be used only for layout once in page.

Although I regret that extend does not have 'attributeAsLocals' like modules.

I wonder why there is three type of similar plugins (include, extend and modules), each one with unique features, instead of single plugin that combine features of this three.