Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nested extends locals are not working #44

Closed
nelsonihc opened this issue Dec 1, 2021 · 4 comments · Fixed by #45
Closed

nested extends locals are not working #44

nelsonihc opened this issue Dec 1, 2021 · 4 comments · Fixed by #45

Comments

@nelsonihc
Copy link
Contributor

Hi, i'm trying to use locals with nested extends block, but it's not working. This use case is interesting for posthtml-extend to create components from code snippets and use them into bigger pages.

<!-- parent.html -->
<div>
    <block name="content"></block>
</div>
<!-- nested.html -->
<div class="nested">
    <span>{{ nested_var }}</span>
    <block name="nested"></block>
</div>
<!-- page.html -->
<extends src="parent.html">
  <block name="content">
        <extends src="nested.html" locals='{"nested_var":"tada!"}'>
          <block name="nested">nested content example</block>
        </extends>
  </block>
</extends>

results in (code is reformatted for readability):

<div class="parent">
    <div class="nested">
        <span>undefined</span>
        nested content example
    </div>        
</div>
@Scrum Scrum linked a pull request Dec 7, 2021 that will close this issue
@Scrum Scrum closed this as completed in #45 Dec 7, 2021
@Scrum
Copy link
Member

Scrum commented Dec 7, 2021

@nelsonihc v0.6.2

@thewebartisan7
Copy link

I try the exact your example with nested extends, but I am getting a compilation error, see below:

What I am missing?

PostHTML Loader: 
  [posthtml-extend] Unexpected block "nested"
  
  
  - PostHTML Loader:
  
  - [posthtml-extend] Unexpected block "nested"
  
  - ModuleBuildError: Module build failed (from ./node_modules/posthtml-loader/lib/index.js):
  
  - PostHTML Loader:
  
  - [posthtml-extend] Unexpected block "nested"
  
  - index.js:158 
    [template-engine]/[posthtml-loader]/lib/index.js:158:10
  
  - NormalModule.js:316 
    [template-engine]/[webpack]/lib/NormalModule.js:316:20
  
  - LoaderRunner.js:367 
    [template-engine]/[loader-runner]/lib/LoaderRunner.js:367:11
  
  - LoaderRunner.js:233 
    [template-engine]/[loader-runner]/lib/LoaderRunner.js:233:18
  
  - LoaderRunner.js:111 context.callback
    [template-engine]/[loader-runner]/lib/LoaderRunner.js:111:13
  
  - index.js:158 
    [template-engine]/[posthtml-loader]/lib/index.js:158:7
  
  - child-compiler.js:131 
    [template-engine]/[html-webpack-plugin]/lib/child-compiler.js:131:18
  
  - Compiler.js:343 
    [template-engine]/[webpack]/lib/Compiler.js:343:11
  
  - Compiler.js:681 
    [template-engine]/[webpack]/lib/Compiler.js:681:15
  
  
  - Hook.js:154 AsyncSeriesHook.lazyCompileHook
    [template-engine]/[tapable]/lib/Hook.js:154:20
  
  - Compiler.js:678 
    [template-engine]/[webpack]/lib/Compiler.js:678:31
  
  
  - Hook.js:154 AsyncSeriesHook.lazyCompileHook
    [template-engine]/[tapable]/lib/Hook.js:154:20
  
  - Compilation.js:1423 
    [template-engine]/[webpack]/lib/Compilation.js:1423:35
  
  
  - Hook.js:154 AsyncSeriesHook.lazyCompileHook
    [template-engine]/[tapable]/lib/Hook.js:154:20
  
  - Compilation.js:1414 
    [template-engine]/[webpack]/lib/Compilation.js:1414:32
  
  
  - Hook.js:154 AsyncSeriesHook.lazyCompileHook
    [template-engine]/[tapable]/lib/Hook.js:154:20
  
  - Compilation.js:1409 
    [template-engine]/[webpack]/lib/Compilation.js:1409:36

@thewebartisan7
Copy link

thewebartisan7 commented Jan 26, 2022

As I understand seem that also parent.html expect a nested block, because it works fine if I add nested block in parent.html, but then content it's duplicated:

<!--  parent.html -->
<div>
    <block name="content"></block>
    <block name="nested">nested content example</block>
</div>

Checking source code of compiled file I see that nested block of page.html it's not compiled:

<!-- parent.html -->
<div>
    
        <!-- nested.html -->
<div class="nested">
    <block name="nested">nested content example</block>
</div>
    
   nested content example
</div>

@thewebartisan7
Copy link

Ok I found that is required to set strict: false: #28

Anyway please add an example in docs about this so next one will spare an hour looking into.

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants