Open piotrpog opened 2 years ago
The sidebar won't show if there are no blocks in it.
It is not possible to have different regions per layout, if you need different regions you'll need to create a theme that extends bootstrap theme and override the regions.
"The sidebar won't show if there are no blocks in it." Yes, but this was just an example, specific to bootstrap theme. It could for example be some other difference, for example one layout has container 1000px wide and other 800px wide. I would like to have option for one layout section to use one layout and for other entry section to use other.
"It is not possible to have different regions per layout, if you need different regions you'll need to create a theme that extends bootstrap theme and override the regions." But i dont want to have different regions per layout - i would like to assign separate layouts do different sections or maybe entries.
Is it possible? We can create custom layouts, so i assumed that these custom layouts could be used somehow.
So your other layout can have different blocks, you can copy the default layout for that specific entry and change the blocks. If you need a specific blocks for a url that is not a category or an entry, then you can create a custom layout.
You can change the displays for each layout also.
Anything else will need to be changed in the template. You can override the displays/region/block template for any entry for example : https://github.com/ryssbowh/craft-themes/wiki/Developers#entry-layouts
If you have a section blog
, an entry type default
and a view mode small
, then this is the list of templates for the displays you can override :
layouts/entry_blog-default_small.twig
layouts/entry_blog_small.twig
layouts/entry_blog-default.twig
layouts/entry_blog.twig
layouts/entry.twig
The default template being here : https://github.com/ryssbowh/craft-themes/blob/master/src/templates/front/layouts/layout.twig
Or if it's a region (for example header
) you need to override :
regions/entry_blog-default_region-header.twig
regions/entry_blog_region-header.twig
regions/entry_blog-default_region.twig
regions/entry_blog_region.twig
regions/entry_region-header.twig
regions/entry_region.twig
The default template being there : https://github.com/ryssbowh/craft-themes/blob/master/src/templates/front/regions/region.twig
All those templates will be listed on the frontend as HTML comments if you enable the templates suggestions : https://github.com/ryssbowh/craft-themes/wiki/Usage#user-preferences-pro
"So your other layout can have different blocks, you can copy the default layout for that specific entry and change the blocks. If you need a specific blocks for a url that is not a category or an entry, then you can create a custom layout." So, from what i understand, the basic "scaffolding" of theme is common for every possible layout. I took a look at bootstrap them and how it defines regions:
protected function defineRegions(): ?array
{
return [
[
'handle' => 'before-header',
'name' => \Craft::t('bootstrap-theme', 'Before Header'),
'width' => '100%',
],
];
}
This means that before header region is defined "globally", not for any specific layouts, but for all of them, existing in this theme. It will exist in every layout, yes?
Next you described how we can overwrite various objects using template files - thanks for that, but i was thinking about something different. Now we are venturing into vague proposals teritory, but i was thinking about defining layouts with DIFFERENT REGIONS, not just with different blocks set in these regions.
This would probably require rewriting parts of code base, but when we take defineRegions
method as example, we would define regions like this:
protected function defineRegions(): ?array
{
return [
[
'handle' => 'before-header',
'name' => \Craft::t('bootstrap-theme', 'Before Header'),
'width' => '100%',
'layourHandles' => ['Default', 'withRIghtSidebar'],
],
[
'handle' => 'sidebar-right',
'name' => \Craft::t('bootstrap-theme', 'Before Header'),
'width' => '100%',
'layourHandles' => ['withRightSidebar'],
],
];
}
This would generate multiple two layout builders, one displaying region sidebar, one not. And end-user would be able to select for example if section "blog" uses layout with sidebar, or not.
I see, I guess we could have themes define one or several "region layouts". Users would be able to choose which they want for each layout in the blocks section. That could work, it's not an easy change though, will have a look
Lets take bootstrap theme - it has default layout with sidebar. But i would also like to have for example layout without sidebar. Is it possible to select layout for specific entry? Or for whole section/entry type? If yes, how do you do that?