Documentation

SproutVariable
in package
uses PropertiesTrait

Access to Sprout helpers from Twig templates.

Additional variables can be added to this namespace using SproutVariable::register(name, item) in a module's sprout_load.php file.

This is registered by SproutExtension.

Use this in your Twig templates like so:

{# Get a file:// url with absroot. #}
{% set fileUrl = sprout.url.file(filePath) %}

{# Require the 'fb' module JS/CSS files. #}
{% do sprout.needs.module('fb') %}

{# Render the CSRF token input. #}
{{ sprout.csrf.token|raw }}

Important things:

  • read the relevant docs for each helper.
  • helpers that return HTML will likely need to be un-escaped with the |raw filter.

Table of Contents

Properties

$admin  : AdminAuth
$captcha  : Captcha
$cookie  : Cookie
$csrf  : Csrf
$enc  : Enc
$errors  : JsErrors
$file  : File
$honeypot  : Honeypot
$lnk  : Lnk
$multiedit  : MultiEdit
$navigation  : Navigation
$needs  : Needs
$notification  : Notification
$page  : Page
$permissions  : UserPerms
$replace  : ContentReplace
$request  : Request
$session  : Session
$skin  : Skin
$social  : array<string|int, mixed>
$text  : Text
$url  : Url
$user  : UserAuthInterface
$widgets  : Widgets
$extra  : mixed

Methods

__call()  : mixed
This proxies calls to functions or variables registered by modules.
__construct()  : mixed
config()  : mixed
Load a config file or config variable.
getParam()  : string|array<string|int, mixed>|null
Get a single GET query parameter, or `null` if missing.
getParams()  : array<string|int, mixed>
Get all GET query params.
getPath()  : string
The request URI.
getProperties()  : array<string|int, string>
Get a list of properties for this object.
getPropertyDefaults()  : array<string|int, mixed>
Get a list of default properties for this object.
getPropertyTypes()  : array<string|int, string>
Get a list of properties, with respective types (if available).
getQueryString()  : string
Get the GET query string.
include()  : Markup
Render a PHP template.
register()  : void
Register a variable or function on the sprout namespace.
require()  : Markup
Render a file, without performing any pre-processing.

Properties

$social

public array<string|int, mixed> $social

[SocialMedia, SocialNetworking]

Methods

__call()

This proxies calls to functions or variables registered by modules.

public __call(string $name, array<string|int, mixed> $arguments) : mixed

Use SproutVariable::register(name, item) in your sprout_load.php files.

Parameters
$name : string
$arguments : array<string|int, mixed>

config()

Load a config file or config variable.

public config(string $name[, bool $slash = false ][, bool $required = true ]) : mixed

aka. Kohana::config()

Parameters
$name : string
$slash : bool = false
$required : bool = true

getParam()

Get a single GET query parameter, or `null` if missing.

public getParam(mixed $name) : string|array<string|int, mixed>|null

aka. $_GET[name]

Parameters
$name : mixed
Return values
string|array<string|int, mixed>|null

getParams()

Get all GET query params.

public getParams() : array<string|int, mixed>

aka. $_GET

Return values
array<string|int, mixed>

getPath()

The request URI.

public getPath() : string

aka. Router::current_uri

Return values
string

getProperties()

Get a list of properties for this object.

public static getProperties() : array<string|int, string>

By default this is a set of non-static public properties, but can be overridden by child classes that might want to show or hide other data.

This is used by:

Return values
array<string|int, string>

getPropertyDefaults()

Get a list of default properties for this object.

public static getPropertyDefaults() : array<string|int, mixed>

By default this is all non-static public properties with compile time default values. That is, defined in the class definition.

Return values
array<string|int, mixed> —

[ name => value ]

getPropertyTypes()

Get a list of properties, with respective types (if available).

public static getPropertyTypes() : array<string|int, string>

Object properties can have strict types. If not typed, all properties will be mixed.

Return values
array<string|int, string> —

[ name => type ]

getQueryString()

Get the GET query string.

public getQueryString() : string

aka. Router::query_string

Return values
string

include()

Render a PHP template.

public include(string $name[, array<string|int, mixed> $data = [] ]) : Markup
Parameters
$name : string
$data : array<string|int, mixed> = []
Tags
throws
Exception
Return values
Markup

register()

Register a variable or function on the sprout namespace.

public static register(string $name, mixed $item) : void

This is for modules to expose additional functionality via the sprout.* namespace in Twig templates.

Call this method in your module sprout_load.php file.

Note, trying to register a name that is a reserved variables (those explicitly declared in this class) will throw an exception.

Parameters
$name : string
$item : mixed

a function reference/closure or variable

Tags
throws
Exception

if the name is a reserved variable

require()

Render a file, without performing any pre-processing.

public require(string $path) : Markup

This uses the skin lookup rules (modules/sprout/skin).

Parameters
$path : string

formatted name.ext

Return values
Markup
On this page

Search results