pooria - 4 days ago

Hi

I just created a new theme. In the layouts directory, there is a default.twig that is the main skeleton of the website. But I need a specific design for the homepage. So I thought I can create a file home.twig in the same layouts directory and extend default.twig and put home entities in its content block; Then I set the home page in the control panel to inherit the new home layout. But It didn't work and the content of the page (Welcome to Pyro...) Replaced all the entities in home.twig.

I think another work around for this is to copy the code of default.twig and put them into home.twig, add homepage elements and remove the {% block content %} section; But that doesn't seem to be really intuitive :(

What can I do?

ryanthompson - 4 days ago

I typically don't extend layouts between them. For example I use a default.twig layout for general purpose pages. Define blocks for header / banner maybe so that the page types can pass things into them.

The home.twig IF I need one usually has a wide content area maybe and then a fancy header/nav area for example. BUT I keep these two totally separate.

The Page Type will dictate what goes into the content block. It's layout code will allow you to define what goes in the content block based on the page fields:

</h1>{{ page.title }}</h1>
{{ page.blocks.render()|raw }}

You can ALSO define the content block inside your page type as well as other blocks if you like too (like a header block). Maybe you have a dropdown of available headers or something:

{% block header %}
    {% include "theme::partials/" ~ page.header.key %}
{% endblock %}

{% block header %}
    </h1>{{ page.title }}</h1>
    {{ page.blocks.render()|raw }}
{% endblock %}

ryanthompson - 4 days ago

Hopefully this answers your question. The layouts really only should serve for wide / container / sidebar pages maybe. BUT.. it is totally up to you. Pyro is extremely flexible, I am just sharing with you what we typically do. We put out a handful of websites every single month so we've got some practice with it :-P

pooria - 3 days ago

@ryanthompson So you mean what I said as the second way would be nice? To separate home page layout (like in Wordpress's front-page.php)