Extension

The CMS Twig extension class implements the basic CMS Twig functions and filters.

 class Cms\Twig\Extension
extends Twig\Extension\AbstractExtension

Properties

protected $controller : Cms\Classes\Controller

The instanciated CMS controller

Methods

public assetsFunction ($type = null) : string | null

Renders registered assets of a given type or all types if $type not provided

Parameters
Property Description
$type
mixed
Returns
string | null

public componentFunction (string $name, array $parameters = []) : string

Renders a component's default partial.

Parameters
Property Description
$name
string
$parameters
array
Returns
string

public contentFunction (string $name, array $parameters = [], boolean $throwException = false) : string | bool

Renders the requested content file.

Parameters
Property Description
$name
string
$parameters
array
$throwException
boolean
Returns
string | bool

public displayBlock (string $name, $default = null) : string | null

Returns a layout block contents (or null if it doesn't exist) and removes the block.

Parameters
Property Description
$name
string
$default
mixed
Returns
string | null

public endBlock (boolean $append = true) : void

Closes a layout block.

Parameters
Property Description
$append
boolean
Returns
void

public getController () : Cms\Classes\Controller

Gets the CMS controller instance

Returns
Cms\Classes\Controller

public getFilters () : array

Returns an array of filters this extension provides.

Returns
array

public getFunctions () : array

Returns an array of functions to add to the existing list.

Returns
array

public getTokenParsers () : array

Returns an array of token parsers this extension provides.

Returns
array

public pageFilter (mixed $name, array $parameters = [], boolean $routePersistence = true) : string | null

Returns the relative URL for the provided page

Parameters
Property Description
$name
mixed

Specifies the Cms Page file name.

$parameters
array

Route parameters to consider in the URL. If boolean will be used as the value for $routePersistence

$routePersistence
boolean

Set to false to exclude the existing routing parameters from the generated URL

Returns
string | null

public pageFunction () : string

Renders a page; used in the layout code to output the requested page.

Returns
string

public partialFunction (string $name, array $parameters = [], boolean $throwException = false) : string | bool

Renders the requested partial with the provided parameters. Optionally throw an exception if the partial cannot be found

Parameters
Property Description
$name
string
$parameters
array
$throwException
boolean
Returns
string | bool

public placeholderFunction (string $name, $default = null) : string | null

Renders placeholder content, without removing the block, must be called before the placeholder tag itself

Parameters
Property Description
$name
string
$default
mixed
Returns
string | null

public setController (Cms\Classes\Controller $controller)

Sets the CMS controller instance

Parameters
Property Description
$controller
Cms\Classes\Controller
Returns
mixed

public startBlock (string $name) : void

Opens a layout block.

Parameters
Property Description
$name
string
Returns
void

public themeFilter (mixed $url) : string

Converts supplied URL to a theme URL relative to the website root. If the URL provided is an array then the files will be combined.

Parameters
Property Description
$url
mixed

Specifies the input to be turned into a URL (arrays will be passed to the AssetCombiner)

Returns
string
Copyright © 2024 Winter CMS