posthtml-extend icon indicating copy to clipboard operation
posthtml-extend copied to clipboard

Breaks with nested extends

Open AdamDemirel opened this issue 5 years ago • 4 comments

container.html:

<div>
  <block name="grid-children">
  </block>
</div>

column.html:

<div>
  <block name="col-children">
  </block>
</div>

index.html: The following works fine as expected:

<extends src="./container.html">
  <block name="grid-children"> -->
     <div>this works</div>
  </block>
</extends>

But the following breaks with Error: [posthtml-extend] Unexpected block "col-children":

<extends src="./container.html">
  <block name="grid-children"> -->
    <extends src="./column.html">
      <block name="grid-children">
        <div>this breaks</div>
      </block>
    </extends>
  </block>
</extends>

AdamDemirel avatar Sep 07 '20 04:09 AdamDemirel

@AdamDemirel Hi, sorry for the long answer. I was unable to reproduce your case https://github.com/posthtml-issues/posthtml-extend-issues-28. Could you make adjustments for reproduction?

Scrum avatar Sep 21 '20 10:09 Scrum

@Scrum I've submitted a PR that duplicates the issue here: https://github.com/posthtml-issues/posthtml-extend-issues-28/pull/1

I've found that setting strict: false allows the build to succeed, so it looks like a bug in the type checking?

bkeepers avatar Oct 24 '20 13:10 bkeepers

I've found that setting strict: false allows the build to succeed, so it looks like a bug in the type checking?

No, this is normal plugin behavior. He counts the block col-children undeclared for ./container.html and throws an exception

Whether the plugin should disallow undeclared block names.

By default, the plugin raises an exception if an undeclared block name is encountered. This can be useful for troubleshooting (i.e. detecting typos in block names), but there are cases where "forward declaring" a block name as an extension point for downstream templates is useful, so this restriction can be lifted by setting the strict option to a false value:

Scrum avatar Oct 26 '20 06:10 Scrum

Oh interesting. I was bashing my head against a wall for several hours trying to figure out why it wasn't working. I think it'd be worth including examples of nested layouts and a warning about the strict checking.

bkeepers avatar Oct 26 '20 20:10 bkeepers