CraftVariable

Type
Class
Namespace
craft\web\twig\variables
Inherits
craft\web\twig\variables\CraftVariable » yii\di\ServiceLocator (opens new window) » yii\base\Component (opens new window) » yii\base\BaseObject (opens new window)
Implements
yii\base\Configurable (opens new window)
Since
3.0.0

Craft defines the craft global template variable.

View source (opens new window)

# Public Properties

# app

Type
craft\web\Application, craft\console\Application, null (opens new window)
Default value
null

The Craft application class

View source (opens new window)

# categoryGroups

Type
craft\web\twig\variables\CategoryGroups
Default value
null

View source (opens new window)

# config

Type
craft\web\twig\variables\Config
Default value
null

View source (opens new window)

# cp

Type
craft\web\twig\variables\Cp
Default value
null

View source (opens new window)

# deprecator

Type
craft\web\twig\variables\Deprecator
Default value
null

View source (opens new window)

# elementIndexes

Type
craft\web\twig\variables\ElementIndexes
Default value
null

View source (opens new window)

# emailMessages

Type
craft\web\twig\variables\EmailMessages
Default value
null

View source (opens new window)

# feeds

Type
craft\web\twig\variables\Feeds
Default value
null

View source (opens new window)

# fields

Type
craft\web\twig\variables\Fields
Default value
null

View source (opens new window)

# globals

Type
craft\web\twig\variables\Globals
Default value
null

View source (opens new window)

# i18n

Type
\craft\web\twig\variables\I18n
Default value
null

View source (opens new window)

# io

Type
craft\web\twig\variables\Io
Default value
null

View source (opens new window)

# rebrand

Type
craft\web\twig\variables\Rebrand
Default value
null

View source (opens new window)

# request

Type
craft\web\twig\variables\Request
Default value
null

View source (opens new window)

# routes

Type
craft\web\twig\variables\Routes
Default value
null

View source (opens new window)

# sections

Type
craft\web\twig\variables\Sections
Default value
null

View source (opens new window)

# session

Type
craft\web\twig\variables\UserSession
Default value
null

View source (opens new window)

# systemSettings

Type
craft\web\twig\variables\SystemSettings
Default value
null

View source (opens new window)

# userGroups

Type
craft\web\twig\variables\UserGroups
Default value
null

View source (opens new window)

# userPermissions

Type
craft\web\twig\variables\UserPermissions
Default value
null

View source (opens new window)

# Public Methods

Method Description
__call() Calls the named method which is not a class method.
__clone() (opens new window) This method is called after the object is created by cloning an existing one.
__construct() Constructor.
__get() (opens new window) Getter magic method.
__isset() (opens new window) Checks if a property value is null.
__set() (opens new window) Sets the value of a component property.
__unset() (opens new window) Sets a component property to be null.
assets() Returns a new asset query (opens new window).
attachBehavior() (opens new window) Attaches a behavior to this component.
attachBehaviors() (opens new window) Attaches a list of behaviors to the component.
behaviors() Returns a list of behaviors that this component should behave as.
canGetProperty() Returns a value indicating whether a property can be read.
canSetProperty() (opens new window) Returns a value indicating whether a property can be set.
categories() Returns a new category query (opens new window).
className() (opens new window) Returns the fully qualified name of this class.
clear() (opens new window) Removes the component from the locator.
detachBehavior() (opens new window) Detaches a behavior from the component.
detachBehaviors() (opens new window) Detaches all behaviors from the component.
ensureBehaviors() (opens new window) Makes sure that the behaviors declared in behaviors() (opens new window) are attached to this component.
entries() Returns a new entry query (opens new window).
get() (opens new window) Returns the component instance with the specified ID.
getBehavior() (opens new window) Returns the named behavior object.
getBehaviors() (opens new window) Returns all behaviors attached to this component.
getComponents() (opens new window) Returns the list of the component definitions or the loaded component instances.
globalSets() Returns a new global set query (opens new window).
has() (opens new window) Returns a value indicating whether the locator has the specified component definition or has instantiated the component.
hasEventHandlers() (opens new window) Returns a value indicating whether there is any handler attached to the named event.
hasMethod() (opens new window) Returns a value indicating whether a method is defined.
hasProperty() (opens new window) Returns a value indicating whether a property is defined for this component.
init() Initializes the object.
isLocalized() Returns whether this site has multiple locales.
locale() Gets the current language in use.
matrixBlocks() Returns a new Matrix block query (opens new window).
off() (opens new window) Detaches an existing event handler from this component.
on() (opens new window) Attaches an event handler to an event.
query() Returns a new generic query.
set() (opens new window) Registers a component definition with this locator.
setComponents() (opens new window) Registers a set of component definitions in this locator.
tags() Returns a new tag query (opens new window).
trigger() (opens new window) Triggers an event.
users() Returns a new user query (opens new window).

# __call()

Calls the named method which is not a class method.

This method will check if any attached behavior has the named method and will execute it if available.

Do not call this method directly as it is a PHP magic method that will be implicitly called when an unknown method is being invoked.

View source (opens new window)

Arguments

Returns

mixed – The method return value

Throws

# __construct()

Constructor.

The default implementation does two things:

  • Initializes the object with the given configuration $config.
  • Call init().

If this method is overridden in a child class, it is recommended that

  • the last parameter of the constructor is a configuration array, like $config here.
  • call the parent implementation at the end of the constructor.

View source (opens new window)

Arguments

# assets()

Returns a new asset query (opens new window).

View source (opens new window)

Arguments

Returns

craft\elements\db\AssetQuery

# behaviors()

Returns a list of behaviors that this component should behave as.

Child classes may override this method to specify the behaviors they want to behave as.

The return value of this method should be an array of behavior objects or configurations indexed by behavior names. A behavior configuration can be either a string specifying the behavior class or an array of the following structure:

'behaviorName' => [
    'class' => 'BehaviorClass',
    'property1' => 'value1',
    'property2' => 'value2',
]

Note that a behavior class must extend from \craft\web\twig\variables\Behavior. Behaviors can be attached using a name or anonymously. When a name is used as the array key, using this name, the behavior can later be retrieved using getBehavior() (opens new window) or be detached using detachBehavior() (opens new window). Anonymous behaviors can not be retrieved or detached.

Behaviors declared in this method will be attached to the component automatically (on demand).

View source (opens new window)

Returns

array (opens new window) – The behavior configurations.

# canGetProperty()

Returns a value indicating whether a property can be read.

A property can be read if:

  • the class has a getter method associated with the specified name (in this case, property name is case-insensitive);
  • the class has a member variable with the specified name (when $checkVars is true);
  • an attached behavior has a readable property of the given name (when $checkBehaviors is true).

View source (opens new window)

Arguments

Returns

boolean (opens new window) – Whether the property can be read

# categories()

Returns a new category query (opens new window).

View source (opens new window)

Arguments

Returns

craft\elements\db\CategoryQuery

# entries()

Returns a new entry query (opens new window).

View source (opens new window)

Arguments

Returns

craft\elements\db\EntryQuery

# globalSets()

Since
3.0.4

Returns a new global set query (opens new window).

View source (opens new window)

Arguments

Returns

craft\elements\db\GlobalSetQuery

# init()

Initializes the object.

This method is invoked at the end of the constructor after the object is initialized with the given configuration.

View source (opens new window)

# isLocalized()

DEPRECATED

Deprecated in 3.0.0. Use craft.app.isMultiSite instead

Returns whether this site has multiple locales.

View source (opens new window)

Returns

boolean (opens new window)

# locale()

DEPRECATED

Deprecated in 3.0.0

Gets the current language in use.

View source (opens new window)

Returns

string (opens new window)

# matrixBlocks()

Returns a new Matrix block query (opens new window).

View source (opens new window)

Arguments

Returns

craft\elements\db\MatrixBlockQuery

# query()

Since
3.0.19

Returns a new generic query.

View source (opens new window)

Returns

craft\db\Query

# tags()

Returns a new tag query (opens new window).

View source (opens new window)

Arguments

Returns

craft\elements\db\TagQuery

# users()

Returns a new user query (opens new window).

View source (opens new window)

Arguments

Returns

craft\elements\db\UserQuery

# Events

# EVENT_DEFINE_BEHAVIORS

Type
craft\events\DefineBehaviorsEvent

The event that is triggered when defining the class behaviors

See also behaviors()

# EVENT_DEFINE_COMPONENTS

DEPRECATED

Deprecated in 3.0.0-beta.23

Type
craft\web\twig\variables\DefineComponentsEvent

The event that is triggered when defining the Service Locator components.

See also __construct()

# EVENT_INIT

Type
yii\base\Event (opens new window)

The event that is triggered after the component's init cycle

See also init()