CraftTwigExtension

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

Class CraftTwigExtension

See also http://craftcms.com

View source

Protected Properties

$environment

Signature

protected Craft\TwigEnvironment $environment = null

Public Methods

MethodDescription
__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

Arguments

Signature

public void __construct ( Craft\TwigEnvironment $environment )

camelFilter()

CamelCases a string.

View source

Arguments

  • $string (string) – The string

Returns

string

Signature

public string camelFilter ( $string )

dateFilter()

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

View source

Arguments

  • $env (\Twig_Environment)
  • $date
  • $format (null)
  • $timezone (null)

Returns

mixed, string

Signature

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

encencFilter()

Encrypts and base64-encodes a string.

View source

Arguments

  • $string (string) – The string.

Returns

string

Signature

public string encencFilter ( $string )

getCsrfInputFunction()

Returns getCsrfInput() wrapped in a \Twig_Markup object.

View source

Returns

\Twig_Markup

Signature

public \Twig_Markup getCsrfInputFunction ( )

getFilters()

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

View source

Returns

array – An array of filters

Signature

public array getFilters ( )

getFootHtmlFunction()

Returns getFootHtml() wrapped in a \Twig_Markup object.

View source

Returns

\Twig_Markup

Signature

public \Twig_Markup getFootHtmlFunction ( )

getFunctions()

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

View source

Returns

array – An array of functions

Signature

public array getFunctions ( )

getGlobals()

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

View source

Returns

array – An array of global variables

Signature

public array getGlobals ( )

getHeadHtmlFunction()

Returns getHeadHtml() wrapped in a \Twig_Markup object.

View source

Returns

\Twig_Markup

Signature

public \Twig_Markup getHeadHtmlFunction ( )

getName()

Returns the name of the extension.

View source

Returns

string – The extension name

Signature

public string getName ( )

getTokenParsers()

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

View source

Returns

array – An array of Twig_TokenParserInterface or Twig_TokenParserBrokerInterface instances

Signature

public array getTokenParsers ( )

groupFilter()

Groups an array by a common property.

View source

Arguments

Returns

array

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

Arguments

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

Returns

integer

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

Arguments

  • $value (mixed) – The value to JSON encode.
  • $options (null, integer) – 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

Arguments

  • $string (string) – The string
  • $glue (string) – The string used to glue the words together (default is a hyphen)
  • $lower (boolean) – Whether the string should be lowercased (default is true)
  • $removePunctuation (boolean) – Whether punctuation marks should be removed (default is true)

Returns

string

Signature

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

lcfirstFilter()

Lowercases the first character of a multibyte string.

View source

Arguments

  • $string (string) – The multibyte string.

Returns

string – 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

Arguments

  • $value (string) – The param value.

Returns

string – The escaped param value.

Signature

public string literalFilter ( $value )

markdownFilter()

Parses text through Markdown.

View source

Arguments

Returns

\Twig_Markup

Signature

public \Twig_Markup markdownFilter ( $str )

parseRefsFilter()

Parses a string for reference tags.

View source

Arguments

Returns

\Twig_Markup

Signature

public \Twig_Markup parseRefsFilter ( $str )

pascalFilter()

PascalCases a string.

View source

Arguments

  • $string (string) – The string

Returns

string

Signature

public string pascalFilter ( $string )

renderObjectTemplate()

View source

Arguments

  • $template
  • $object

Returns

string

Signature

public string renderObjectTemplate ( $template, $object )

replaceFilter()

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

View source

Arguments

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

Returns

mixed

Signature

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

shuffleFunction()

Shuffles an array.

View source

Arguments

  • $arr (mixed)

Returns

mixed

Signature

public mixed shuffleFunction ( $arr )

snakeFilter()

Snake_cases a string.

View source

Arguments

  • $string (string) – The string

Returns

string

Signature

public string snakeFilter ( $string )

ucfirstFilter()

Uppercases the first character of a multibyte string.

View source

Arguments

  • $string (string) – The multibyte string.

Returns

string – The string with the first character converted to upercase.

Signature

public string ucfirstFilter ( $string )

withoutFilter()

Returns an array without certain values.

View source

Arguments

  • $arr (array)
  • $exclude (mixed)

Returns

array

Signature

public array withoutFilter ( $arr, $exclude )