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

Question - how can we select layout for specific entry/section? #22

Open
piotrpog opened this issue Sep 4, 2022 · 5 comments
Open

Question - how can we select layout for specific entry/section? #22

piotrpog opened this issue Sep 4, 2022 · 5 comments
Assignees
Labels
enhancement New feature or request

Comments

@piotrpog
Copy link

piotrpog commented Sep 4, 2022

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?

@ryssbowh
Copy link
Owner

ryssbowh commented Sep 5, 2022

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.

@piotrpog
Copy link
Author

piotrpog commented Sep 5, 2022

"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.

@ryssbowh
Copy link
Owner

ryssbowh commented Sep 7, 2022

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

@piotrpog
Copy link
Author

piotrpog commented Sep 7, 2022

"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.

@ryssbowh
Copy link
Owner

ryssbowh commented Sep 8, 2022

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

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

No branches or pull requests

2 participants