Craft 3 Class Reference

Class craft\web\View

Inheritance
craft\web\View » yii\web\View » yii\base\View » yii\base\Component » yii\base\BaseObject
Implements
yii\base\Configurable, yii\base\DynamicContentAwareInterface
Available since version
3.0
Source Code
https://github.com/craftcms/cms/blob/master/src/web/View.php

Public Properties
Property Type Description Defined By
$assetBundles yii\web\AssetBundle List of the registered asset bundles. yii\web\View
$blocks array A list of named output blocks. yii\base\View
$cacheStack array, yii\base\DynamicContentAwareInterface A list of currently active dynamic content class instances. yii\base\View
$context yii\base\ViewContextInterface The context under which the renderFile() method is being invoked. yii\base\View
$css array The registered CSS code blocks. yii\web\View
$cssFiles array The registered CSS files. yii\web\View
$defaultExtension string The default view file extension. yii\base\View
$dynamicPlaceholders array A list of placeholders for embedding dynamic contents. yii\base\View
$js array The registered JS code blocks yii\web\View
$jsFiles array The registered JS files. yii\web\View
$linkTags array The registered link tags. yii\web\View
$metaTags array The registered meta tags. yii\web\View
$params mixed Custom parameters that are shared among view templates. yii\base\View
$renderers array A list of available renderers indexed by their corresponding supported file extensions. yii\base\View
$theme yii\base\Theme, array, string The theme object or the configuration for creating the theme object. yii\base\View
$title string The page title yii\web\View
Public Methods
Method Description Defined By
__call() Calls the named method which is not a class method. yii\base\BaseObject
__clone() This method is called after the object is created by cloning an existing one. yii\base\Component
__construct() Constructor. yii\base\BaseObject
__get() Returns the value of an object property. yii\base\BaseObject
__isset() Checks if a property is set, i.e. defined and not null. yii\base\BaseObject
__set() Sets value of an object property. yii\base\BaseObject
__unset() Sets an object property to null. yii\base\BaseObject
addDynamicPlaceholder() {@inheritdoc} yii\base\View
afterRender() This method is invoked right after renderFile() renders a view file. yii\base\View
afterRenderPageTemplate() Performs actions after a page template is rendered. craft\web\View
afterRenderTemplate() Performs actions after a template is rendered. craft\web\View
attachBehavior() Attaches a behavior to this component. yii\base\Component
attachBehaviors() Attaches a list of behaviors to the component. yii\base\Component
beforeRender() This method is invoked right before renderFile() renders a view file. yii\base\View
beforeRenderPageTemplate() Performs actions before a page template is rendered. craft\web\View
beforeRenderTemplate() Performs actions before a template is rendered. craft\web\View
beginBlock() Begins recording a block. yii\base\View
beginBody() Marks the beginning of an HTML body section. yii\web\View
beginCache() Begins fragment caching. yii\base\View
beginContent() Begins the rendering of content that is to be decorated by the specified view. yii\base\View
beginPage() Marks the beginning of a page. yii\base\View
behaviors() Returns a list of behaviors that this component should behave as. yii\base\Component
canGetProperty() Returns a value indicating whether a property can be read. yii\base\BaseObject
canSetProperty() Returns a value indicating whether a property can be set. yii\base\BaseObject
className() Returns the fully qualified name of this class. yii\base\BaseObject
clear() Clears up the registered meta tags, link tags, css/js scripts and files. yii\web\View
clearJsBuffer() Clears and ends a JavaScript buffer, returning whatever JavaScript code was included while the buffer was active. craft\web\View
createTwig() Creates a new Twig environment. craft\web\View
detachBehavior() Detaches a behavior from the component. yii\base\Component
detachBehaviors() Detaches all behaviors from the component. yii\base\Component
doesTemplateExist() Returns whether a template exists. craft\web\View
endBlock() Ends recording a block. yii\base\View
endBody() Marks the ending of an HTML body section. craft\web\View
endCache() Ends fragment caching. yii\base\View
endContent() Ends the rendering of content. yii\base\View
endPage() Marks the ending of a page. yii\base\View
ensureBehaviors() Makes sure that the behaviors declared in behaviors() are attached to this component. yii\base\Component
evaluateDynamicContent() Evaluates the given PHP statements. yii\base\View
formatInputId() Formats an ID out of an input name. craft\web\View
getAssetManager() Registers the asset manager being used by this view object. yii\web\View
getBehavior() Returns the named behavior object. yii\base\Component
getBehaviors() Returns all behaviors attached to this component. yii\base\Component
getBodyHtml() Returns the content to be inserted at the end of the body section. craft\web\View
getCpTemplateRoots() Returns any registered CP template roots. craft\web\View
getDynamicContents() Returns a list of currently active dynamic content class instances. yii\base\View
getDynamicPlaceholders() {@inheritdoc} yii\base\View
getHeadHtml() Returns the content to be inserted in the head section. craft\web\View
getIsRenderingPageTemplate() Returns whether a page template is currently being rendered. craft\web\View
getIsRenderingTemplate() Returns whether a template is currently being rendered. craft\web\View
getNamespace() Returns the active namespace. craft\web\View
getSiteTemplateRoots() Returns any registered site template roots. craft\web\View
getTemplateMode() Returns the current template mode (either 'site' or 'cp'). craft\web\View
getTemplatesPath() Returns the base path that templates should be found in. craft\web\View
getTwig() Returns the Twig environment. craft\web\View
getViewFile() yii\base\View
hasEventHandlers() Returns a value indicating whether there is any handler attached to the named event. yii\base\Component
hasMethod() Returns a value indicating whether a method is defined. yii\base\BaseObject
hasProperty() Returns a value indicating whether a property is defined. yii\base\BaseObject
head() Marks the position of an HTML head section. yii\web\View
hook() Queues up a method to be called by a given template hook. craft\web\View
init() Initializes the view component. craft\web\View
invokeHook() Invokes a template hook. craft\web\View
namespaceInputId() Namespaces an input ID. craft\web\View
namespaceInputName() Namespaces an input name. craft\web\View
namespaceInputs() Renames HTML input names so they belong to a namespace. craft\web\View
off() Detaches an existing event handler from this component. yii\base\Component
on() Attaches an event handler to an event. yii\base\Component
popDynamicContent() Removes a last class instance supporting dynamic contents from a list of currently active dynamic content class instances. yii\base\View
pushDynamicContent() Adds a class instance supporting dynamic contents to the end of a list of currently active dynamic content class instances. yii\base\View
registerAssetBundle() Registers the named asset bundle. yii\web\View
registerCsrfMetaTags() Registers CSRF meta tags. yii\web\View
registerCss() Registers a CSS code block. yii\web\View
registerCssFile() Registers a CSS file. yii\web\View
registerHiResCss() Registers a hi-res CSS code block. craft\web\View
registerJs() Registers a JS code block. craft\web\View
registerJsFile() Registers a JS file. yii\web\View
registerJsVar() Registers a JS code block defining a variable. The name of variable will be used as key, preventing duplicated variable names. yii\web\View
registerLinkTag() Registers a link tag. yii\web\View
registerMetaTag() Registers a meta tag. yii\web\View
registerScript() Registers a generic <script> code block. craft\web\View
registerTranslations() Translates messages for a given translation category, so they will be available for Craft.t() calls in the Control Panel. craft\web\View
registerTwigExtension() Registers a new Twig extension, which will be added on existing environments and queued up for future environments. craft\web\View
render() Renders a view. yii\base\View
renderAjax() Renders a view in response to an AJAX request. yii\web\View
renderDynamic() Renders dynamic content returned by the given PHP statements. yii\base\View
renderFile() Renders a view file. yii\base\View
renderObjectTemplate() Renders a micro template for accessing properties of a single object. craft\web\View
renderPageTemplate() Renders a Twig template that represents an entire web page. craft\web\View
renderPhpFile() Renders a view file as a PHP script. yii\base\View
renderString() Renders a template defined in a string. craft\web\View
renderTemplate() Renders a Twig template. craft\web\View
renderTemplateMacro() Renders a macro within a given Twig template. craft\web\View
resolveTemplate() Finds a template on the file system and returns its path. craft\web\View
setAssetManager() Sets the asset manager. yii\web\View
setDynamicPlaceholders() {@inheritdoc} yii\base\View
setNamespace() Sets the active namespace. craft\web\View
setTemplateMode() Sets the current template mode. craft\web\View
setTemplatesPath() Sets the base path that templates should be found in. craft\web\View
startJsBuffer() Starts a JavaScript buffer. craft\web\View
trigger() Triggers an event. yii\base\Component
Protected Methods
Method Description Defined By
findViewFile() Finds the view file based on the given view name. yii\base\View
registerAllAssetFiles() Registers all files provided by all registered asset bundles, including depending bundles files. craft\web\View
registerAssetFiles() Registers all files provided by an asset bundle including depending bundles files. yii\web\View
registerAssetFlashes() Registers any asset bundles and JS code that were queued-up in the session flash data. craft\web\View
renderBodyBeginHtml() Renders the content to be inserted at the beginning of the body section. craft\web\View
renderBodyEndHtml() Renders the content to be inserted at the end of the body section. craft\web\View
renderHeadHtml() Renders the content to be inserted in the head section. craft\web\View
Events
Event Type Description Defined By
EVENT_AFTER_RENDER yii\base\ViewEvent An event that is triggered by renderFile() right after it renders a view file. yii\base\View
EVENT_AFTER_RENDER_PAGE_TEMPLATE craft\events\TemplateEvent The event that is triggered after a page template gets rendered craft\web\View
EVENT_AFTER_RENDER_TEMPLATE craft\events\TemplateEvent The event that is triggered after a template gets rendered craft\web\View
EVENT_BEFORE_RENDER yii\base\ViewEvent An event that is triggered by renderFile() right before it renders a view file. yii\base\View
EVENT_BEFORE_RENDER_PAGE_TEMPLATE craft\events\TemplateEvent The event that is triggered before a page template gets rendered craft\web\View
EVENT_BEFORE_RENDER_TEMPLATE craft\events\TemplateEvent The event that is triggered before a template gets rendered craft\web\View
EVENT_BEGIN_BODY \yii\web\Event An event that is triggered by beginBody(). yii\web\View
EVENT_BEGIN_PAGE yii\base\Event An event that is triggered by beginPage(). yii\base\View
EVENT_END_BODY \yii\web\Event An event that is triggered by endBody(). yii\web\View
EVENT_END_PAGE yii\base\Event An event that is triggered by endPage(). yii\base\View
EVENT_REGISTER_CP_TEMPLATE_ROOTS craft\events\RegisterTemplateRootsEvent The event that is triggered when registering CP template roots craft\web\View
EVENT_REGISTER_SITE_TEMPLATE_ROOTS craft\events\RegisterTemplateRootsEvent The event that is triggered when registering site template roots craft\web\View
Constants
Constant Value Description Defined By
PH_BODY_BEGIN '' This is internally used as the placeholder for receiving the content registered for the beginning of the body section. yii\web\View
PH_BODY_END '' This is internally used as the placeholder for receiving the content registered for the end of the body section. yii\web\View
PH_HEAD '' This is internally used as the placeholder for receiving the content registered for the head section. yii\web\View
POS_BEGIN 2 The location of registered JavaScript code block or files. This means the location is at the beginning of the body section. yii\web\View
POS_END 3 The location of registered JavaScript code block or files. This means the location is at the end of the body section. yii\web\View
POS_HEAD 1 The location of registered JavaScript code block or files. This means the location is in the head section. yii\web\View
POS_LOAD 5 The location of registered JavaScript code block. This means the JavaScript code block will be enclosed within jQuery(window).load(). yii\web\View
POS_READY 4 The location of registered JavaScript code block. This means the JavaScript code block will be enclosed within jQuery(document).ready(). yii\web\View
TEMPLATE_MODE_CP 'cp' craft\web\View
TEMPLATE_MODE_SITE 'site' craft\web\View

Method Details

afterRenderPageTemplate() public method #

Performs actions after a page template is rendered.

public void afterRenderPageTemplate ( \craft\web\string $template, array $variables, \craft\web\string &$output )
$template mixed The name of the template that was rendered
$variables array The variables that were available to the template
$output string The template’s rendering result

afterRenderTemplate() public method #

Performs actions after a template is rendered.

public void afterRenderTemplate ( \craft\web\string $template, array $variables, \craft\web\string &$output )
$template mixed The name of the template that was rendered
$variables array The variables that were available to the template
$output string The template’s rendering result

beforeRenderPageTemplate() public method #

Performs actions before a page template is rendered.

public boolean beforeRenderPageTemplate ( \craft\web\string $template, array &$variables )
$template mixed The name of the template to render
$variables
return boolean Whether the template should be rendered

beforeRenderTemplate() public method #

Performs actions before a template is rendered.

public boolean beforeRenderTemplate ( \craft\web\string $template, array &$variables )
$template mixed The name of the template to render
$variables
return boolean Whether the template should be rendered

clearJsBuffer() public method #

Clears and ends a JavaScript buffer, returning whatever JavaScript code was included while the buffer was active.

public string, false clearJsBuffer ( \craft\web\bool $scriptTag true )
$scriptTag boolean Whether the JavaScript code should be wrapped in a <script> tag. Defaults to true.
return string, false The JS code that was included in the active JS buffer, or false if there isn’t one

createTwig() public method #

Creates a new Twig environment.

public craft\web\twig\Environment createTwig ( )

doesTemplateExist() public method #

Returns whether a template exists.

Internally, this will just call resolveTemplate() with the given template name, and return whether that method found anything.

public boolean doesTemplateExist ( \craft\web\string $name )
$name string The name of the template.
return boolean Whether the template exists.

endBody() public method #

Marks the ending of an HTML body section.

public void endBody ( )

formatInputId() public method #

Formats an ID out of an input name.

This method takes a given input name and returns a valid ID based on it. For example, if given the following input name:

foo[bar][title]

the following ID would be returned:

foo-bar-title
public string formatInputId ( \craft\web\string $inputName )
$inputName string The input name.
return string The input ID.

getBodyHtml() public method #

Returns the content to be inserted at the end of the body section.

This includes:

public string getBodyHtml ( \craft\web\bool $clear true )
$clear boolean Whether the content should be cleared from the queue (default is true)
return string The rendered content

getCpTemplateRoots() public method #

Returns any registered CP template roots.

public array getCpTemplateRoots ( )

getHeadHtml() public method #

Returns the content to be inserted in the head section.

This includes:

public string getHeadHtml ( \craft\web\bool $clear true )
$clear boolean Whether the content should be cleared from the queue (default is true)
return string The rendered content

getIsRenderingPageTemplate() public method #

Returns whether a page template is currently being rendered.

public boolean getIsRenderingPageTemplate ( )
return boolean Whether a page template is currently being rendered.

getIsRenderingTemplate() public method #

Returns whether a template is currently being rendered.

public boolean getIsRenderingTemplate ( )
return boolean Whether a template is currently being rendered.

getNamespace() public method #

Returns the active namespace.

This is the default namespaces that will be used when namespaceInputs(), namespaceInputName(), and namespaceInputId() are called, if their $namespace arguments are null.

public string, null getNamespace ( )
return string, null The namespace.

getSiteTemplateRoots() public method #

Returns any registered site template roots.

public array getSiteTemplateRoots ( )

getTemplateMode() public method #

Returns the current template mode (either 'site' or 'cp').

public string getTemplateMode ( )
return string Either 'site' or 'cp'.

getTemplatesPath() public method #

Returns the base path that templates should be found in.

public string getTemplatesPath ( )

getTwig() public method #

Returns the Twig environment.

public craft\web\twig\Environment getTwig ( )

hook() public method #

Queues up a method to be called by a given template hook.

For example, if you place this in your plugin’s \craft\web\BasePlugin::init() method:

Craft::$app->view->hook('myAwesomeHook', function(&$context) {
    $context['foo'] = 'bar';
    return 'Hey!';
});

you would then be able to add this to any template:

{% hook "myAwesomeHook" %}

When the hook tag gets invoked, your template hook function will get called. The $context argument will be the current Twig context array, which you’re free to manipulate. Any changes you make to it will be available to the template following the tag. Whatever your template hook function returns will be output in place of the tag in the template as well.

public void hook ( \craft\web\string $hook, $method )
$hook string The hook name.
$method callback The callback function.

init() public method #

Initializes the view component.

public void init ( )

invokeHook() public method #

Invokes a template hook.

This is called by \craft\web\HookNode.

public string invokeHook ( \craft\web\string $hook, array &$context )
$hook string The hook name.
$context
return string Whatever the hooks returned.

namespaceInputId() public method #

Namespaces an input ID.

This method applies the same namespacing treatment that namespaceInputs() does to id= attributes, but only to a single value, which is passed directly into this method.

public string namespaceInputId ( \craft\web\string $inputId, \craft\web\string $namespace null )
$inputId string The input ID that should be namespaced.
$namespace string, null The namespace. Defaults to the active namespace.
return string The namespaced input ID.

namespaceInputName() public method #

Namespaces an input name.

This method applies the same namespacing treatment that namespaceInputs() does to name= attributes, but only to a single value, which is passed directly into this method.

public string namespaceInputName ( \craft\web\string $inputName, \craft\web\string $namespace null )
$inputName string The input name that should be namespaced.
$namespace string, null The namespace. Defaults to the active namespace.
return string The namespaced input name.

namespaceInputs() public method #

Renames HTML input names so they belong to a namespace.

This method will go through the passed-in $html looking for name= attributes, and renaming their values such that they will live within the passed-in $namespace (or the active namespace). By default, any id=, for=, list=, data-target=, data-reverse-target=, and data-target-prefix= attributes will get namespaced as well, by prepending the namespace and a dash to their values. For example, the following HTML:

<label for="title">Title</label>
<input type="text" name="title" id="title">

would become this, if it were namespaced with “foo”:

<label for="foo-title">Title</label>
<input type="text" name="foo[title]" id="foo-title">

Attributes that are already namespaced will get double-namespaced. For example, the following HTML:

<label for="bar-title">Title</label>
<input type="text" name="bar[title]" id="title">

would become:

<label for="foo-bar-title">Title</label>
<input type="text" name="foo[bar][title]" id="foo-bar-title">
public string namespaceInputs ( \craft\web\string $html, \craft\web\string $namespace null, \craft\web\bool $otherAttributes true )
$html string The template with the inputs.
$namespace string, null The namespace. Defaults to the active namespace.
$otherAttributes boolean Whether id=, for=, etc., should also be namespaced. Defaults to true.
return string The HTML with namespaced input names.

registerAllAssetFiles() protected method #

Registers all files provided by all registered asset bundles, including depending bundles files.

Removes a bundle from $assetBundles once files are registered.

protected void registerAllAssetFiles ( )

registerAssetFlashes() protected method #

Registers any asset bundles and JS code that were queued-up in the session flash data.

protected void registerAssetFlashes ( )
throws yii\base\Exception if any of the registered asset bundles are not actually asset bundles

registerHiResCss() public method #

Deprecated in 3.0. Use registerCss() and type your own media selector.

Registers a hi-res CSS code block.

public void registerHiResCss ( \craft\web\string $css, array $options = [], \craft\web\string $key null )
$css string The CSS code block to be registered
$options array The HTML attributes for the style tag.
$key string, null The key that identifies the CSS code block. If null, it will use $css as the key. If two CSS code blocks are registered with the same key, the latter will overwrite the former.

registerJs() public method #

Registers a JS code block.

public void registerJs ( $js, $position self::POS_READY, $key null )
$js string The JS code block to be registered
$position integer The position at which the JS script tag should be inserted in a page. The possible values are: POS_HEAD: in the head section POS_BEGIN: at the beginning of the body section POS_END: at the end of the body section POS_LOAD: enclosed within jQuery(window).load(). Note that by using this position, the method will automatically register the jQuery js file. POS_READY: enclosed within jQuery(document).ready(). This is the default value. Note that by using this position, the method will automatically register the jQuery js file.
$key string The key that identifies the JS code block. If null, it will use $js as the key. If two JS code blocks are registered with the same key, the latter will overwrite the former.

registerScript() public method #

Registers a generic <script> code block.

public void registerScript ( $script, $position self::POS_END, $options = [], $key null )
$script string The generic <script> code block to be registered
$position integer The position at which the generic <script> code block should be inserted in a page. The possible values are: POS_HEAD: in the head section POS_BEGIN: at the beginning of the body section POS_END: at the end of the body section
$options array The HTML attributes for the <script> tag.
$key string The key that identifies the generic <script> code block. If null, it will use $script as the key. If two generic <script> code blocks are registered with the same key, the latter will overwrite the former.

registerTranslations() public method #

Translates messages for a given translation category, so they will be available for Craft.t() calls in the Control Panel.

Note this should always be called before any JavaScript is registered that will need to use the translations, unless the JavaScript is registered at self::POS_READY.

public void registerTranslations ( \craft\web\string $category, array $messages )
$category string The category the messages are in
$messages string[] The messages to be translated

registerTwigExtension() public method #

Registers a new Twig extension, which will be added on existing environments and queued up for future environments.

public void registerTwigExtension ( Twig_ExtensionInterface $extension )
$extension Twig_ExtensionInterface

renderBodyBeginHtml() protected method #

Renders the content to be inserted at the beginning of the body section.

The content is rendered using the registered JS code blocks and files.

protected string renderBodyBeginHtml ( )
return string The rendered content

renderBodyEndHtml() protected method #

Renders the content to be inserted at the end of the body section.

The content is rendered using the registered JS code blocks and files.

protected string renderBodyEndHtml ( $ajaxMode )
$ajaxMode boolean Whether the view is rendering in AJAX mode. If true, the JS scripts registered at POS_READY and POS_LOAD positions will be rendered at the end of the view like normal scripts.
return string The rendered content

renderHeadHtml() protected method #

Renders the content to be inserted in the head section.

The content is rendered using the registered meta tags, link tags, CSS/JS code blocks and files.

protected string renderHeadHtml ( )
return string The rendered content

renderObjectTemplate() public method #

Renders a micro template for accessing properties of a single object.

The template will be parsed for {variables} that are delimited by single braces, which will get replaced with full Twig output tags, i.e. {{ object.variable }}. Regular Twig tags are also supported.

public string renderObjectTemplate ( \craft\web\string $template, $object, array $variables = [] )
$template string The source template string
$object mixed The object that should be passed into the template
$variables array Any additional variables that should be available to the template
return string The rendered template.
throws yii\base\Exception in case of failure
throws RuntimeException in case of failure

renderPageTemplate() public method #

Renders a Twig template that represents an entire web page.

public string renderPageTemplate ( \craft\web\string $template, array $variables = [] )
$template string The name of the template to load
$variables array The variables that should be available to the template
return string The rendering result

renderString() public method #

Renders a template defined in a string.

public string renderString ( \craft\web\string $template, array $variables = [] )
$template string The source template string.
$variables array Any variables that should be available to the template.
return string The rendered template.

renderTemplate() public method #

Renders a Twig template.

public string renderTemplate ( \craft\web\string $template, array $variables = [] )
$template string The name of the template to load
$variables array The variables that should be available to the template
return string The rendering result
throws Twig_Error_Loader if the template doesn’t exist
throws yii\base\Exception in case of failure
throws RuntimeException in case of failure

renderTemplateMacro() public method #

Renders a macro within a given Twig template.

public string renderTemplateMacro ( \craft\web\string $template, \craft\web\string $macro, array $args = [] )
$template string The name of the template the macro lives in.
$macro string The name of the macro.
$args array Any arguments that should be passed to the macro.
return string The rendered macro output.
throws yii\base\Exception in case of failure
throws RuntimeException in case of failure

resolveTemplate() public method #

Finds a template on the file system and returns its path.

All of the following files will be searched for, in this order:

If this is a front-end request, the actual list of file extensions and index filenames are configurable via the defaultTemplateExtensions and indexTemplateFilenames config settings.

For example if you set the following in config/general.php:

'defaultTemplateExtensions' => ['htm'],
'indexTemplateFilenames' => ['default'],

then the following files would be searched for instead:

The actual directory that those files will depend on the current template mode (probably templates/ if it’s a front-end site request, and vendor/craftcms/cms/src/templates/ if it’s a Control Panel request).

If this is a front-end site request, a folder named after the current site handle will be checked first.

And finally, if this is a Control Panel request and the template name includes multiple segments and the first segment of the template name matches a plugin’s handle, then Craft will look for a template named with the remaining segments within that plugin’s templates/ subfolder.

To put it all together, here’s where Craft would look for a template named “foo/bar”, depending on the type of request it is:

public string, false resolveTemplate ( \craft\web\string $name )
$name string The name of the template.
return string, false The path to the template if it exists, or false.

setNamespace() public method #

Sets the active namespace.

This is the default namespaces that will be used when namespaceInputs(), namespaceInputName(), and namespaceInputId() are called, if their|null $namespace arguments are null.

public void setNamespace ( \craft\web\string $namespace null )
$namespace string, null The new namespace. Set to null to remove the namespace.

setTemplateMode() public method #

Sets the current template mode.

The template mode defines:

public void setTemplateMode ( \craft\web\string $templateMode )
$templateMode string Either 'site' or 'cp'
throws yii\base\Exception if $templateMode is invalid

setTemplatesPath() public method #

Sets the base path that templates should be found in.

public void setTemplatesPath ( \craft\web\string $templatesPath )
$templatesPath string

startJsBuffer() public method #

Starts a JavaScript buffer.

JavaScript buffers work similarly to output buffers in PHP. Once you’ve started a JavaScript buffer, any JavaScript code included with registerJs() will be included in a buffer, and you will have the opportunity to fetch all of that code via clearJsBuffer() without having it actually get output to the page.

public void startJsBuffer ( )

Event Details

EVENT_AFTER_RENDER_PAGE_TEMPLATE event of type craft\events\TemplateEvent #

The event that is triggered after a page template gets rendered

EVENT_AFTER_RENDER_TEMPLATE event of type craft\events\TemplateEvent #

The event that is triggered after a template gets rendered

EVENT_BEFORE_RENDER_PAGE_TEMPLATE event of type craft\events\TemplateEvent #

The event that is triggered before a page template gets rendered

EVENT_BEFORE_RENDER_TEMPLATE event of type craft\events\TemplateEvent #

The event that is triggered before a template gets rendered

EVENT_REGISTER_CP_TEMPLATE_ROOTS event of type craft\events\RegisterTemplateRootsEvent #

The event that is triggered when registering CP template roots

EVENT_REGISTER_SITE_TEMPLATE_ROOTS event of type craft\events\RegisterTemplateRootsEvent #

The event that is triggered when registering site template roots