Template
- Type
- Class
- Namespace
- craft\helpers
- Inherits
- craft\helpers\Template
- Since
- 3.0.0
Class Template
View source (opens new window)
# Public Methods
Method | Description |
---|---|
beginProfile() | Begins profiling a template element. |
css() | Registers a CSS file or a CSS code block. |
endProfile() | Finishes profiling a template element. |
js() | Registers a JS file or a JS code block. |
paginateCriteria() | Paginates a query. |
paginateQuery() | Paginates a query. |
raw() | Returns a string wrapped in a \Twig\Markup object |
resolveTemplatePathAndLine() | Attempts to resolve a compiled template file path and line number to its source template path and line number. |
# beginProfile()
- Since
- 3.3.0
Begins profiling a template element.
View source (opens new window)
Arguments
$type
(string (opens new window)) – The type of template element being profiled ('template', 'block', or 'macro')$name
(string (opens new window)) – The name of the template element
# css()
- Since
- 3.5.6
Registers a CSS file or a CSS code block.
View source (opens new window)
Arguments
$css
(string (opens new window)) – The CSS file URL, or the content of the CSS code block to be registered$options
(array (opens new window)) – The HTML attributes for the<link>
/<style>
tag.$key
(string (opens new window), null (opens new window)) – 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.
Throws
# endProfile()
- Since
- 3.3.0
Finishes profiling a template element.
View source (opens new window)
Arguments
$type
(string (opens new window)) – The type of template element being profiled ('template', 'block', or 'macro')$name
(string (opens new window)) – The name of the template element
# js()
- Since
- 3.5.6
Registers a JS file or a JS code block.
View source (opens new window)
Arguments
$js
(string (opens new window)) – The JS file URL, or the content of the JS code block to be registered$options
(array (opens new window)) – The HTML attributes for the<script>
tag.$key
(string (opens new window), null (opens new window)) – The key that identifies the JS code block. If null, it will use $css as the key. If two JS code blocks are registered with the same key, the latter will overwrite the former.
Throws
# paginateCriteria()
DEPRECATED
Deprecated in 3.6.0. Use paginateQuery() instead.
Paginates a query.
View source (opens new window)
Arguments
Returns
# paginateQuery()
- Since
- 3.6.0
Paginates a query.
View source (opens new window)
Arguments
Returns
# raw()
Returns a string wrapped in a \Twig\Markup object
View source (opens new window)
Arguments
$value
(string (opens new window))
Returns
\Twig\Markup
# resolveTemplatePathAndLine()
- Since
- 3.7.49
Attempts to resolve a compiled template file path and line number to its source template path and line number.
View source (opens new window)
Arguments
$path
(string (opens new window)) – The compiled template path$line
(integer (opens new window), null (opens new window)) – The line number from the compiled template
Returns
array (opens new window), false (opens new window) – The resolved template path and line number, or false
if the path couldn’t be determined.
If a template path could be determined but not the template line number, the line number will be null.
# Constants
Constant | Description |
---|---|
PROFILE_STAGE_BEGIN | |
PROFILE_STAGE_END | |
PROFILE_TYPE_BLOCK | |
PROFILE_TYPE_MACRO | |
PROFILE_TYPE_TEMPLATE |