Cms\Twig\Extension
Overview
Extension implements the basic CMS Twig functions and filters.
Extends
- Twig\Extension\AbstractExtension
Implements
- Twig\Extension\ExtensionInterface
- Twig\Extension\LastModifiedExtensionInterface
Protected Properties
protected Cms\Classes\Controller $controller
controller reference
protected array $putOnceCache
putOnceCache stores the cache for yieldBlockOnce
Public Methods
public __construct()
public __construct($controller = null): void
__construct the extension instance.
public abortFunction()
public abortFunction(int $code, string|false $message = ''): void
abortFunction will abort the successful page cycle
public static addExtensionToTwig()
public static addExtensionToTwig($twig, $controller = null): void
addExtensionToTwig adds this extension to the Twig environment and also creates a hook for others.
public ajaxHandlerFunction()
public ajaxHandlerFunction(
string $name = '',
array|null $postVars = null
): void
ajaxHandlerFunction runs an ajax handler
public assetsFunction()
public assetsFunction($type = null): string
assetsFunction renders registered assets of a given type
public componentFunction()
public componentFunction(string $name, array $parameters = []): string
componentFunction renders a component's default content.
public contentFilter()
public contentFilter(string $content): string
contentFilter processes content for links and snippets
public contentFunction()
public contentFunction(
$name,
$parameters = [],
$throwException = false
): string
contentFunction renders a partial based on the file name. The parameters are an optional list of view variables, otherwise pass false to render nothing and check the existence. An exception can be thrown if nothing is found.
public displayBlock()
public displayBlock(string $name, string $default = null): string|null
displayBlock returns a layout block contents and removes the block.
public endBlock()
public endBlock($append = true): void
public flashFunction()
public flashFunction(string $type = null): void
flashFunction returns flash messages as an object
public getFilters()
public getFilters(): array
getFilters returns a list of filters this extension provides.
public getFunctions()
public getFunctions(): array
getFunctions returns a list of functions to add to the existing list.
public getNodeVisitors()
public getNodeVisitors(): array
getNodeVisitors returns a list of node visitors this extension provides.
public getTokenParsers()
public getTokenParsers(): array
getTokenParsers returns a list of token parsers this extension provides.
public hasContentFunction()
public hasContentFunction($name): bool
hasContentFunction checks the content existence without rendering it.
public hasPartialFunction()
public hasPartialFunction($name): bool
hasPartialFunction checks the partials existence without rendering it.
public hasPlaceholderFunction()
public hasPlaceholderFunction($name): void
hasPlaceholderFunction checks that a placeholder exists without rendering it
public pageFilter()
public pageFilter(
mixed $name,
array $parameters = [],
bool $routePersistence = true
): string
pageFilter looks up the URL for a supplied page name and returns it relative to the website root, including route parameters. Parameters can be persisted from the current page parameters.
public pageFunction()
public pageFunction(array|null $context = null): string
pageFunction renders a page. This function should be used in the layout code to output the requested page.
public partialFunction()
public partialFunction(
$name,
$parameters = [],
$throwException = false
): string
partialFunction renders a partial based on the partial name. The parameters are an optional list of view variables. An exception can be thrown if nothing is found.
public placeholderFunction()
public placeholderFunction($name, $default = null): string
placeholderFunction renders a placeholder content, without removing the block, must be called before the placeholder tag itself
public redirectFunction()
public redirectFunction(string $to, int $code = [], $code = 302): void
redirectFunction will redirect the response to a theme page or URL
public responseFunction()
public responseFunction(
Illuminate\Contracts\View\View|string|array|null $content = '',
int|null $status = null,
array $headers = []
): void
responseFunction returns a new response from the application.
public setBlock()
public setBlock($name, $value): void
setBlock sets a block name as a variable value.
public setCache()
public setCache($key, $ttl, $callable): string
public startBlock()
public startBlock($name): void
public themeFilter()
public themeFilter(mixed $url): string
themeFilter 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.
public viteFunction()
public viteFunction(
array|string $entryPoints,
string $buildDirectory = 'assets/dist'
): string
viteFunction renders the tags for Vite entry points built inside the theme, eg: {{ vite(['assets/css/theme.css', 'assets/js/app.js']) }}
public vueComponentsFunction()
public vueComponentsFunction(): string
vueComponentsFunction renders the Vue client and any registered Vue component templates
public yieldBlock()
public yieldBlock($name, $callable, $append = true): void
yieldBlock yields the contents of a block by appending or overwriting, and storing its name alongside the content.
public yieldBlockOnce()
public yieldBlockOnce(
$templateName,
$placeholderName,
$callable,
$append = false
): void
yieldBlockOnce will append or set some content once per template (partial)
Inherited Public Methods
- getExpressionParsers() - (defined in Twig\Extension\AbstractExtension)
- getLastModified() - (defined in Twig\Extension\AbstractExtension)
- getOperators() - (defined in Twig\Extension\AbstractExtension)
- getTests() - (defined in Twig\Extension\AbstractExtension)