Craft Themes (4.x)

ThemeInterface

A theme is a regular plugin, it defines regions and can extend another theme.

They can be partials. They define preferences for rendering page elements.

Table of Contents

afterSet()  : mixed
Callback after the theme has been set for a request
afterThemeInstall()  : mixed
Callback after the plugin is installed, this is only called for pro version.
afterThemeUninstall()  : mixed
Callback after the plugin is uninstalled.
getAssetUrl()  : string
Get an url for an theme asset.
getDefaultRegionLayout()  : RegionLayoutInterface
Get the default region layout
getDefaultRegionLayoutHandle()  : string|null
Get the default region layout handle. Returning null will take the handle from the parent theme.
getExtends()  : string|null
Which other theme does this extends from.
getHasPreview()  : bool
Does this theme have a preview image
getParent()  : ThemeInterface|null
Get theme parent
getPreferences()  : ThemePreferencesInterface
Get theme preferences
getPreviewImage()  : string
Preview image for the theme, returns a web url
getRegionLayout()  : array<string|int, mixed>
Get a region layout by handle. Will return the default region layout if $handle is null
getRegionLayouts()  : array<string|int, mixed>
Get theme's region layouts definitions
getRegionsTemplate()  : string
Get the base template for rendering regions
getScssCompiler()  : Compiler
Get the scss compiler.
getTemplatePaths()  : array<string|int, string>
Absolute template paths, including those of the parent(s)
getTemplatesFolder()  : string
Folder where the templates are stored for this theme
isPartial()  : bool
Is this theme partial.
registerAssetBundles()  : mixed
Register this theme's assets in view for a specific path

Methods

afterSet()

Callback after the theme has been set for a request

public afterSet() : mixed
Return values
mixed

afterThemeInstall()

Callback after the plugin is installed, this is only called for pro version.

public afterThemeInstall() : mixed

At this point the theme data (layouts etc) is installed.

Return values
mixed

afterThemeUninstall()

Callback after the plugin is uninstalled.

public afterThemeUninstall() : mixed

At this point the theme data (layouts etc) is uninstalled.

Return values
mixed

getAssetUrl()

Get an url for an theme asset.

public getAssetUrl(string $path) : string
Parameters
$path : string
Return values
string

getDefaultRegionLayoutHandle()

Get the default region layout handle. Returning null will take the handle from the parent theme.

public getDefaultRegionLayoutHandle() : string|null
Tags
since
5.0.0
Return values
string|null

getExtends()

Which other theme does this extends from.

public getExtends() : string|null

Returns a plugin handle.

Return values
string|null

getHasPreview()

Does this theme have a preview image

public getHasPreview() : bool
Return values
bool

getPreviewImage()

Preview image for the theme, returns a web url

public getPreviewImage() : string
Return values
string

getRegionLayout()

Get a region layout by handle. Will return the default region layout if $handle is null

public getRegionLayout([string|null $handle = null ]) : array<string|int, mixed>
Parameters
$handle : string|null = null
Tags
since
5.0.0
Return values
array<string|int, mixed>

getRegionLayouts()

Get theme's region layouts definitions

public getRegionLayouts() : array<string|int, mixed>
Tags
since
5.0.0
Return values
array<string|int, mixed>

getRegionsTemplate()

Get the base template for rendering regions

public getRegionsTemplate(RegionLayout $layout) : string
Parameters
$layout : RegionLayout
Return values
string

getScssCompiler()

Get the scss compiler.

public getScssCompiler([array<string|int, mixed> $options = [] ]) : Compiler

To ensure paths inheritance for parent themes is kept, compiler option importPaths must be set here. The compiler defined here will be used for asset bundle scss, inline scss and files, and command line compilations.

Parameters
$options : array<string|int, mixed> = []

Override compiler options here. Import paths will be prepended, aliases will be overridden

Return values
Compiler

getTemplatePaths()

Absolute template paths, including those of the parent(s)

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

getTemplatesFolder()

Folder where the templates are stored for this theme

public getTemplatesFolder() : string
Return values
string

isPartial()

Is this theme partial.

public isPartial() : bool

Partial themes can't be selected for front end, their purpose is only to be inherited from

Return values
bool

registerAssetBundles()

Register this theme's assets in view for a specific path

public registerAssetBundles(string $urlPath) : mixed
Parameters
$urlPath : string
Return values
mixed

Search results