philicevic / mix-html-builder

A quick laravel mix extension to build up html templates from partials and layouts.
MIT License
19 stars 8 forks source link

Multiple layouts extends #18

Closed weblabio closed 3 years ago

weblabio commented 4 years ago

Tell me, please, is it possible to use templates in this way?

home.html

<extends src="default">
   <block name="content">Home Page</block>
</extends>

layouts/default.html

<extends src="app">
   <block name="layout">
        <header>...</header>
        <main>
            <block name="content" />
        </main>
       <footer>...</footer>
   </block>
</extends>

layouts/app.html

<head>...</head>
<body>
     <block name="layout" />
</body>

home -> layouts/default -> layouts/app so you can use many intermediate layers instead of layouts/default and having a basic immutable layer (layouts/app)

Now, if I use the code above, I get an error: [posthtml-extend] Unexpected block "content"

If I rename layout to content inside layouts/app.html then the contents of layouts/default.html is ignored

my solution looks dirty, such a template should be in every page, layout default can be changed for individual pages:

<include src="start.html" locals='{
    "pageTitle": "HomePage",
    "pageClass": "page-home"
}'></include>

<extends src="default.html">
    <block name="content">
        <h1>Welcome!</h1>
    </block>
</extends>

<include src="end.html"></include>
philicevic commented 3 years ago

I don't think that i can do much about it, as the functionality depends on posthtml-extend. If anyone finds a way to do this, feel free to open a PR. But I myself won't try to implement this right now.