Layouts (Pro)
Layouts are created by the system automatically, their types as mentioned in this wiki are as follows :
- Default :
default - Entry types :
entry - Category groups :
category - Global sets :
global - Tag groups :
tag - Users :
user - Volumes :
volume - Products :
product - Variants :
variant - Custom :
custom
Custom layouts
You can add a custom layout programmatically by doing :
$layout = Themes::$plugin->layouts->createCustom([
'name' => 'My Layout',
'elementUid' => 'handle',
'themeHandle' => 'theme-handle'
]);
$layout->blocks = $someBlocks;
Themes::$plugin->layouts->save($layout);
//Or copy an existing one
$defaultLayout = Themes::$plugin->layouts->getDefault('theme-handle');
$layout = Themes::$plugin->layouts->copyIntoCustom($defaultLayout, 'name', 'handle');
Render it in a twig template :
{% set layout = craft.themes.layouts.getCustom(craft.themes.current, 'handle') %}
{{ layout.renderRegions()|raw }}
And delete it :
Themes::$plugin->layouts->deleteCustom($layout);
To render the content block for a custom template, follow the block template precedence described in the templating page.