SproutExtension
extends AbstractExtension
in package
implements
GlobalsInterface
This is a set of extension functions/filters for Twig templates.
A list of core twig filters + function can be found here:
- https://twig.symfony.com/doc/3.x/filters/index.html
- https://twig.symfony.com/doc/3.x/functions/index.html
This extension also provides core global variables for sprout:
- IN_PRODUCTION
- DOCROOT
- sprout SproutVariable
- now
Table of Contents
Interfaces
- GlobalsInterface
Methods
- attr() : string
- Render a hash keys into an attribute string.
- bustyUrl() : string
- Create a URL with a timestamp for cache busting purposes.
- cc2kc() : string
- Changes camelCase to kebab-case
- getFilters() : mixed
- getFunctions() : mixed
- getGlobals() : array<string|int, mixed>
- getTests() : mixed
- jsdate() : string
- A wrapper around strtotime. Pretty handy.
- jsonPretty() : string
- Shorthand pretty print JSON.
- kc2cc() : string
- Changes kebab-case to camelCase
- options() : string
- Render hash keys into a string, depending on the truthiness of the value.
- push() : array<string|int, mixed>
- shuffle() : array<string|int, mixed>
- truncate() : string
- Trim a string if it's too long. Adds a ... ellipsis character.
- unshift() : array<string|int, mixed>
- url() : string
- Build a URL on the absolute root.
Methods
attr()
Render a hash keys into an attribute string.
public
attr(array<string|int, mixed> $config) : string
Special rules apply for these types:
null|falseare excluded from the outputtrue|emptyonly includes the key, without the value- numeric values are always included
Example:
# attr({abc: 0, def: '', ghi: 'foo', hjk: null})
> 'abc="0" def ghi="foo"'
All keys and values are html escaped.
Parameters
- $config : array<string|int, mixed>
Return values
stringbustyUrl()
Create a URL with a timestamp for cache busting purposes.
public
bustyUrl(string $url) : string
Parameters
- $url : string
-
The URL as provided by the Twig template.
Return values
stringcc2kc()
Changes camelCase to kebab-case
public
cc2kc(string|null $var) : string
Use kebab() instead
Parameters
- $var : string|null
Return values
stringgetFilters()
public
getFilters() : mixed
Tags
getFunctions()
public
getFunctions() : mixed
Tags
getGlobals()
public
getGlobals() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed>getTests()
public
getTests() : mixed
Tags
jsdate()
A wrapper around strtotime. Pretty handy.
public
jsdate(mixed $value) : string
Parameters
- $value : mixed
Return values
stringjsonPretty()
Shorthand pretty print JSON.
public
jsonPretty(mixed $data) : string
Parameters
- $data : mixed
Return values
stringkc2cc()
Changes kebab-case to camelCase
public
kc2cc(string|null $var) : string
Use camel() instead
Parameters
- $var : string|null
Return values
stringoptions()
Render hash keys into a string, depending on the truthiness of the value.
public
options(array<string|int, mixed> $options) : string
Example:
# options({abc: 123, def: '', ghi: 'foo'})
> 'abc ghi'
All values are html escaped.
Parameters
- $options : array<string|int, mixed>
Return values
stringpush()
public
push(array<string|int, mixed> $array, mixed ...$items) : array<string|int, mixed>
Parameters
- $array : array<string|int, mixed>
- $items : mixed
Return values
array<string|int, mixed>shuffle()
public
shuffle(array<string|int, mixed> $array[, bool $preserve_keys = false ]) : array<string|int, mixed>
Parameters
- $array : array<string|int, mixed>
- $preserve_keys : bool = false
Return values
array<string|int, mixed>truncate()
Trim a string if it's too long. Adds a ... ellipsis character.
public
truncate(null|string $text, int $length) : string
Parameters
- $text : null|string
- $length : int
Return values
stringunshift()
public
unshift(array<string|int, mixed> $array, mixed ...$items) : array<string|int, mixed>
Parameters
- $array : array<string|int, mixed>
- $items : mixed
Return values
array<string|int, mixed>url()
Build a URL on the absolute root.
public
url([string|null $path = null ][, array<string|int, mixed>|null $params = null ]) : string
Provide 'params' to build a query string.
The result is URL safe.
Parameters
- $path : string|null = null
- $params : array<string|int, mixed>|null = null