CraftTwigExtension

Type
Class
Namespace
Craft
Inherits
Craft\CraftTwigExtension » Twig_Extension
Since
2.0

Class CraftTwigExtension

See also http://craftcms.com

View source (opens new window)

# Protected Properties

Property Description
$environment Craft\TwigEnvironment

# $environment

Signature

protected Craft\TwigEnvironment $environment = null

# Public Methods

Method Description
__construct() CraftTwigExtension constructor.
camelFilter() CamelCases a string.
dateFilter() Extending Twig's
encencFilter() Encrypts and base64-encodes a string.
getCsrfInputFunction() Returns getCsrfInput() wrapped in a \Twig_Markup object.
getFilters() Returns a list of filters to add to the existing list.
getFootHtmlFunction() Returns getFootHtml() wrapped in a \Twig_Markup object.
getFunctions() Returns a list of functions to add to the existing list.
getGlobals() Returns a list of global variables to add to the existing list.
getHeadHtmlFunction() Returns getHeadHtml() wrapped in a \Twig_Markup object.
getName() Returns the name of the extension.
getTokenParsers() Returns the token parser instances to add to the existing list.
groupFilter() Groups an array by a common property.
indexOfFilter() Returns the index of an item in a string or array, or -1 if it cannot be found.
jsonEncodeFilter() This method will JSON encode a variable. We're overriding Twig's default implementation to set some stricter encoding options on text/html/xml requests.
kebabFilter() Kebab-cases a string.
lcfirstFilter() Lowercases the first character of a multibyte string.
literalFilter() Escapes commas and asterisks in a string so they are not treated as special characters in {@link DbHelper::parseParam()}.
markdownFilter() Parses text through Markdown.
parseRefsFilter() Parses a string for reference tags.
pascalFilter() PascalCases a string.
renderObjectTemplate()
replaceFilter() Replaces Twig's
shuffleFunction() Shuffles an array.
snakeFilter() Snake_cases a string.
ucfirstFilter() Uppercases the first character of a multibyte string.
withoutFilter() Returns an array without certain values.

# __construct()

CraftTwigExtension constructor.

View source (opens new window)

Arguments

Signature

public void __construct ( Craft\TwigEnvironment $environment )

# camelFilter()

CamelCases a string.

View source (opens new window)

Arguments

Returns

string (opens new window)

Signature

public string camelFilter ( $string )

# dateFilter()

Extending Twig's |date filter so we can run any translations on the output.

View source (opens new window)

Arguments

Returns

mixed, string (opens new window)

Signature

public mixed, string dateFilter ( \Twig_Environment $env, $date, $format = null, $timezone = null )

# encencFilter()

Encrypts and base64-encodes a string.

View source (opens new window)

Arguments

Returns

string (opens new window)

Signature

public string encencFilter ( $string )

# getCsrfInputFunction()

Returns getCsrfInput() wrapped in a \Twig_Markup object.

View source (opens new window)

Returns

\Twig_Markup

Signature

public \Twig_Markup getCsrfInputFunction ( )

# getFilters()

Returns a list of filters to add to the existing list.

View source (opens new window)

Returns

array (opens new window) – An array of filters

Signature

public array getFilters ( )

# getFootHtmlFunction()

Returns getFootHtml() wrapped in a \Twig_Markup object.

View source (opens new window)

Returns

\Twig_Markup

Signature

public \Twig_Markup getFootHtmlFunction ( )

# getFunctions()

Returns a list of functions to add to the existing list.

View source (opens new window)

Returns

array (opens new window) – An array of functions

Signature

public array getFunctions ( )

# getGlobals()

Returns a list of global variables to add to the existing list.

View source (opens new window)

Returns

array (opens new window) – An array of global variables

Signature

public array getGlobals ( )

# getHeadHtmlFunction()

Returns getHeadHtml() wrapped in a \Twig_Markup object.

View source (opens new window)

Returns

\Twig_Markup

Signature

public \Twig_Markup getHeadHtmlFunction ( )

# getName()

Returns the name of the extension.

View source (opens new window)

Returns

string (opens new window) – The extension name

Signature

public string getName ( )

# getTokenParsers()

Returns the token parser instances to add to the existing list.

View source (opens new window)

Returns

array (opens new window) – An array of Twig_TokenParserInterface or Twig_TokenParserBrokerInterface instances

Signature

public array getTokenParsers ( )

# groupFilter()

Groups an array by a common property.

View source (opens new window)

Arguments

Returns

array (opens new window)

Signature

public array groupFilter ( $arr, $item )

# indexOfFilter()

Returns the index of an item in a string or array, or -1 if it cannot be found.

View source (opens new window)

Arguments

  • $haystack (mixed)
  • $needle (mixed)

Returns

integer (opens new window)

Signature

public integer indexOfFilter ( $haystack, $needle )

# jsonEncodeFilter()

This method will JSON encode a variable. We're overriding Twig's default implementation to set some stricter encoding options on text/html/xml requests.

View source (opens new window)

Arguments

  • $value (mixed) – The value to JSON encode.
  • $options (null (opens new window), integer (opens new window)) – Either null or a bitmask consisting of JSON_HEX_QUOT, JSON_HEX_TAG, JSON_HEX_AMP, JSON_HEX_APOS, JSON_NUMERIC_CHECK, JSON_PRETTY_PRINT, JSON_UNESCAPED_SLASHES, JSON_FORCE_OBJECT

Returns

mixed – The JSON encoded value.

Signature

public mixed jsonEncodeFilter ( $value, $options = null )

# kebabFilter()

Kebab-cases a string.

View source (opens new window)

Arguments

Returns

string (opens new window)

Signature

public string kebabFilter ( $string, $glue = '-', $lower = true, $removePunctuation = true )

# lcfirstFilter()

Lowercases the first character of a multibyte string.

View source (opens new window)

Arguments

Returns

string (opens new window) – The string with the first character converted to lowercase.

Signature

public string lcfirstFilter ( $string )

# literalFilter()

Escapes commas and asterisks in a string so they are not treated as special characters in {@link DbHelper::parseParam()}.

View source (opens new window)

Arguments

Returns

string (opens new window) – The escaped param value.

Signature

public string literalFilter ( $value )

# markdownFilter()

Parses text through Markdown.

View source (opens new window)

Arguments

Returns

\Twig_Markup

Signature

public \Twig_Markup markdownFilter ( $str )

# parseRefsFilter()

Parses a string for reference tags.

View source (opens new window)

Arguments

Returns

\Twig_Markup

Signature

public \Twig_Markup parseRefsFilter ( $str )

# pascalFilter()

PascalCases a string.

View source (opens new window)

Arguments

Returns

string (opens new window)

Signature

public string pascalFilter ( $string )

# renderObjectTemplate()

View source (opens new window)

Arguments

  • $template
  • $object

Returns

string (opens new window)

Signature

public string renderObjectTemplate ( $template, $object )

# replaceFilter()

Replaces Twig's |replace filter, adding support for passing in separate search and replace arrays.

View source (opens new window)

Arguments

  • $str (mixed)
  • $search (mixed)
  • $replace (mixed)

Returns

mixed

Signature

public mixed replaceFilter ( $str, $search, $replace = null )

# shuffleFunction()

Shuffles an array.

View source (opens new window)

Arguments

  • $arr (mixed)

Returns

mixed

Signature

public mixed shuffleFunction ( $arr )

# snakeFilter()

Snake_cases a string.

View source (opens new window)

Arguments

Returns

string (opens new window)

Signature

public string snakeFilter ( $string )

# ucfirstFilter()

Uppercases the first character of a multibyte string.

View source (opens new window)

Arguments

Returns

string (opens new window) – The string with the first character converted to upercase.

Signature

public string ucfirstFilter ( $string )

# withoutFilter()

Returns an array without certain values.

View source (opens new window)

Arguments

Returns

array (opens new window)

Signature

public array withoutFilter ( $arr, $exclude )