Craft Themes (3.x)

LayoutInterface

A layout is associated to a theme and unless it's a custom layout, to a Craft element.

Those elements can be : entry type, category group, global set, volume, tag group or user layout. Layouts have regions, as defined by their theme.

Table of Contents

RENDER_MODE_DISPLAYS  = 'displays'
RENDER_MODE_REGIONS  = 'regions'
addBlock()  : LayoutInterface
Add a block
addViewMode()  : LayoutInterface
Add a view mode
canHaveBlocks()  : bool
Can this layout be assigned blocks
getBlocks()  : array<string|int, BlockInterface>
Blocks getter
getBlockTemplates()  : array<string|int, mixed>
Get available templates for a block
getConfig()  : array<string|int, mixed>
Get project config
getCraftFields()  : array<string|int, Field>
Get all craft fields defined on this layout's element
getDefaultViewMode()  : ViewModeInterface
Get default view mode
getDescription()  : string
Get description
getEditBlocksUrl()  : string
Get the url to edit blocks.
getEditDisplaysUrl()  : string|null
Get the url to edit displays for a view mode.
getElement()  : mixed
Get element associated to that layout (category group, entry type, User etc)
getFieldLayout()  : FieldLayout
Get layout's element field layout
getFieldTemplates()  : array<string|int, mixed>
Get available templates for a field
getFileTemplates()  : array<string|int, mixed>
Get available templates for a file
getGroupTemplates()  : array<string|int, mixed>
Get available templates for a group
getParent()  : LayoutInterface|null
Parent getter
getRegion()  : Region
Get a region by handle.
getRegions()  : array<string|int, RegionInterface>
Get layout regions
getRegionTemplates()  : array<string|int, mixed>
Get available templates for a region
getTemplates()  : array<string|int, mixed>
Get available templates
getTemplatingKey()  : string
Get the portion of template name associated with this element.
getTheme()  : ThemeInterface
Get this layout's theme
getType()  : string
Type getter
getViewMode()  : ViewModeInterface|null
Get view mode by handle
getViewModes()  : array<string|int, ViewModeInterface>
Get view modes defined for that layout
hasDisplays()  : bool
Can this layout define displays.
hasRegion()  : bool
Is a region defined
hasViewMode()  : bool
Is a view mode handle defined in this layout
render()  : Markup
Render this layout for an element
renderRegions()  : Markup
Render this layout's regions
setBlocks()  : LayoutInterface
Blocks setter
setElement()  : mixed
Set element associated to that layout
setParent()  : mixed
Parent setter
setViewModes()  : LayoutInterface
View modes setter

Constants

Methods

canHaveBlocks()

Can this layout be assigned blocks

public canHaveBlocks() : bool
Return values
bool

getBlockTemplates()

Get available templates for a block

public getBlockTemplates(BlockInterface $block) : array<string|int, mixed>
Parameters
$block : BlockInterface
Return values
array<string|int, mixed>

getConfig()

Get project config

public getConfig() : array<string|int, mixed>
Return values
array<string|int, mixed>

getCraftFields()

Get all craft fields defined on this layout's element

public getCraftFields() : array<string|int, Field>
Return values
array<string|int, Field>

getDescription()

Get description

public getDescription() : string
Return values
string

getEditBlocksUrl()

Get the url to edit blocks.

public getEditBlocksUrl() : string

Returns the blocks url for the default layout if this layout doesn't have blocks

Return values
string

getEditDisplaysUrl()

Get the url to edit displays for a view mode.

public getEditDisplaysUrl([ViewModeInterface|string|null $viewMode = null ]) : string|null

Returns null if the layout doesn't have displays. Takes the default view mode if $viewMode is null

Parameters
$viewMode : ViewModeInterface|string|null = null
Return values
string|null

getElement()

Get element associated to that layout (category group, entry type, User etc)

public getElement() : mixed
Return values
mixed

getFieldLayout()

Get layout's element field layout

public getFieldLayout() : FieldLayout
Return values
FieldLayout

getFieldTemplates()

Get available templates for a field

public getFieldTemplates(FieldInterface $field) : array<string|int, mixed>
Parameters
$field : FieldInterface
Return values
array<string|int, mixed>

getGroupTemplates()

Get available templates for a group

public getGroupTemplates(GroupInterface $group) : array<string|int, mixed>
Parameters
$group : GroupInterface
Return values
array<string|int, mixed>

getRegion()

Get a region by handle.

public getRegion(string $handle) : Region
Parameters
$handle : string
Return values
Region

getTemplatingKey()

Get the portion of template name associated with this element.

public getTemplatingKey() : string

This would be 'blog-article' for an entry type 'article' of a section 'blog'. Or 'authors' for a category group 'authors' Etc

Return values
string

getType()

Type getter

public getType() : string
Return values
string

hasDisplays()

Can this layout define displays.

public hasDisplays() : bool

Default and custom layout can't have displays since it doesn't have an element associated to it.

Return values
bool

hasRegion()

Is a region defined

public hasRegion(string $handle) : bool
Parameters
$handle : string
Return values
bool

hasViewMode()

Is a view mode handle defined in this layout

public hasViewMode(string $handle) : bool
Parameters
$handle : string
Return values
bool

render()

Render this layout for an element

public render(Element $element[, string|ViewModeInterface $viewMode = ViewModeService::DEFAULT_HANDLE ]) : Markup
Parameters
$element : Element
$viewMode : string|ViewModeInterface = ViewModeService::DEFAULT_HANDLE
Return values
Markup

renderRegions()

Render this layout's regions

public renderRegions() : Markup
Return values
Markup

setElement()

Set element associated to that layout

public setElement(mixed $element) : mixed
Parameters
$element : mixed
Return values
mixed

Search results