Documentation

TwigView extends BaseView
in package

Renderer for twig engine

Twig view are located with with same loader rules as PHP views, requiring a sprout/modules/skin prefix.

Sprout provides a set of functions + filters as well as the core extensions:

  • https://twig.symfony.com/doc/3.x/filters/index.html
  • https://twig.symfony.com/doc/3.x/functions/index.html
  • SproutExtension

Sprout exposes a global sprout variable for helpers and modules. SproutVariable

Table of Contents

Properties

$DEBUG_COMMENT  : mixed
$EXTENSION  : mixed
$kohana_filename  : mixed
$kohana_global_data  : array<string, mixed>
$kohana_local_data  : array<string, mixed>
$kohana_template_name  : string
$loader  : TwigSkinLoader
$twig  : Environment

Methods

__construct()  : mixed
Attempts to load a view and pre-load view data.
__get()  : mixed
Magically gets a view variable.
__isset()  : bool
Magic method access to test for view property
__set()  : void
Magically sets a view variable.
__toString()  : string
Magically converts view object to string.
bind()  : object
Sets a bound variable by reference.
create()  : BaseView
Not actually deprecated - this will always exist.
decodeErrorFrame()  : array<string|int, mixed>|null
Fetch real trace information for a twig template.
exists()  : bool
Does this template exist?
getDebugComment()  : string
A debug comment indicates where this view is being loaded.
getSkinType()  : string
The View class to use for the current skin.
getTwig()  : Environment
include()  : string
Shorthand load and render a view.
isPropertySet()  : bool|array<string|int, mixed>
Checks for a property existence in the view locally or globally. Unlike the built in __isset(), this method can take an array of properties to test simultaneously.
processBacktrace()  : array<string|int, mixed>
Process twig components of a backtrace.
render()  : ($print is true ? void : string)
Renders a view.
renderString()  : string
Render an inline twig template.
set()  : object
Sets a view variable.
setFilename()  : object
Sets the view filename.
setGlobal()  : void
Sets a view global variable.
skin()  : BaseView
Same as create() but enforces that only skin templates will be loaded.

Properties

$DEBUG_COMMENT

public static mixed $DEBUG_COMMENT = !IN_PRODUCTION

$EXTENSION

protected static mixed $EXTENSION = '.twig'

$kohana_filename

protected mixed $kohana_filename = FALSE

$kohana_global_data

protected static array<string, mixed> $kohana_global_data = []

$kohana_local_data

protected array<string, mixed> $kohana_local_data = []

$kohana_template_name

protected string $kohana_template_name

$twig

protected static Environment $twig

Methods

__construct()

Attempts to load a view and pre-load view data.

public __construct(mixed $name[, array<string|int, mixed> $data = [] ]) : mixed
Parameters
$name : mixed

view name

$data : array<string|int, mixed> = []

pre-load data

Tags
inheritdoc

__get()

Magically gets a view variable.

public & __get(string $key) : mixed
Parameters
$key : string

variable key

Return values
mixed —

variable value if the key is found or void if the key is not found

__isset()

Magic method access to test for view property

public __isset([string $key = null ]) : bool
Parameters
$key : string = null

View property to test for

Return values
bool

__set()

Magically sets a view variable.

public __set(string $key, mixed $value) : void
Parameters
$key : string

variable key

$value : mixed

variable value

__toString()

Magically converts view object to string.

public __toString() : string
Return values
string

bind()

Sets a bound variable by reference.

public bind(string $name, mixed &$var) : object
Parameters
$name : string

name of variable

$var : mixed

variable to assign by reference

Return values
object

create()

Not actually deprecated - this will always exist.

public static create(string $name[, mixed $data = [] ]) : BaseView

Use BaseView::create().

Just for clarity please use the base class.

Parameters
$name : string
$data : mixed = []
Return values
BaseView

decodeErrorFrame()

Fetch real trace information for a twig template.

public static decodeErrorFrame(string $file[, int|null $line = null ]) : array<string|int, mixed>|null

The result includes a mapped file path, line number, and source code.

Parameters
$file : string

Compiled template path

$line : int|null = null

Trace line number

Return values
array<string|int, mixed>|null —

[ file, line, code ]

exists()

Does this template exist?

public static exists(string $name) : bool

This abides by dynamic-skin loading rules for different view types. So if the skin is set to 'twig' it'll search for 'skin/etc/view.twig'.

Parameters
$name : string
Tags
throws
Kohana_Exception
Exception
Return values
bool

getDebugComment()

A debug comment indicates where this view is being loaded.

public getDebugComment() : string

This is injected into the rendered output. It's only enabled given the static DEBUG_COMMENT property - default matches IN_PRODUCTION.

This only appears in HTML/XML output.

Return values
string

getSkinType()

The View class to use for the current skin.

public static getSkinType() : string
Return values
string —

a class name

getTwig()

public static getTwig() : Environment
Return values
Environment

include()

Shorthand load and render a view.

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

isPropertySet()

Checks for a property existence in the view locally or globally. Unlike the built in __isset(), this method can take an array of properties to test simultaneously.

public isPropertySet([array<string|int, mixed>|string|false $key = false ]) : bool|array<string|int, mixed>
Parameters
$key : array<string|int, mixed>|string|false = false

property name to test for or array of property names to test for

Return values
bool|array<string|int, mixed> —

property test result or associative array of keys and boolean test result

processBacktrace()

Process twig components of a backtrace.

public static processBacktrace(array<string|int, mixed> $trace[, bool $clean = true ]) : array<string|int, mixed>

Backtrace renders should read the 'source' key to get the source code sample for the current line. This should replace the class->method(args) component.

Parameters
$trace : array<string|int, mixed>
$clean : bool = true
Return values
array<string|int, mixed>

render()

Renders a view.

public render([mixed $print = false ][, mixed $renderer = false ]) : ($print is true ? void : string)
Parameters
$print : mixed = false

set to TRUE to echo the output instead of returning it

$renderer : mixed = false

Special renderer callback to pass the output through

Tags
inheritdoc
Return values
($print is true ? void : string) —

Return the view as a string, or null if print is FALSE

renderString()

Render an inline twig template.

public static renderString(string $template[, array<string|int, mixed> $data = [] ]) : string
Parameters
$template : string
$data : array<string|int, mixed> = []
Return values
string

set()

Sets a view variable.

public set(string|array<string|int, mixed> $name[, mixed $value = null ]) : object
Parameters
$name : string|array<string|int, mixed>

name of variable or an array of variables

$value : mixed = null

value when using a named variable

Return values
object

setFilename()

Sets the view filename.

public setFilename(string $name) : object
Parameters
$name : string

The view filename

Tags
chainable
Return values
object

setGlobal()

Sets a view global variable.

public static setGlobal(string|array<string|int, mixed> $name[, mixed $value = null ]) : void
Parameters
$name : string|array<string|int, mixed>

name of variable or an array of variables

$value : mixed = null

value when using a named variable

skin()

Same as create() but enforces that only skin templates will be loaded.

public static skin(string $name[, array<string|int, mixed> $data = [] ]) : BaseView

This can be particularly useful because most (all) modules and core templates do not offer both a PHP and a Twig template, so performing skin-dynamic loading is somewhat pointless.

Use this if you're unsure. Perhaps the name 'skin()' will make it's behaviour more obvious.

Parameters
$name : string
$data : array<string|int, mixed> = []
Tags
throws
Exception

An invalid skin path

Return values
BaseView
On this page

Search results