class Simple implements View_Interface (View source)

\Yaf\View\Simple is the built-in template engine in Yaf, it is a simple but fast template engine, and only support PHP script template.

Properties

protected string $_tpl_dir
protected array $_tpl_vars
protected array $_options

Methods

__construct(string $template_dir, array $options = null)

No description

__isset(string $name)

No description

bool
assign(string|array $name, mixed $value = null)

assign variable to view engine

string
render(string $tpl, array $tpl_vars = null)

No description

bool
display(string $tpl, array $tpl_vars = null)

Render a template and display the result instantly.

assignRef(string $name, mixed $value)

unlike \Yaf\View\Simple::assign(), this method assign a ref value to engine.

clear(string $name = null)

clear assigned variable

setScriptPath(string $template_dir)

No description

string
getScriptPath()

No description

mixed
__get(null $name = null)

Retrieve assigned variable


Note:

$name parameter can be empty since 2.1.11

__set(string $name, mixed $value = null)

This is a alternative and easier way to \Yaf\View\Simple::assign().

void|bool
eval(string $tpl_str, array $vars = null)

Render a string template and return the result.

Details

final __construct(string $template_dir, array $options = null)

No description

Parameters

string $template_dir

The base directory of the templates, by default, it is APPLICATION . "/views" for Yaf.

array $options

Options for the engine, as of Yaf 2.1.13, you can use short tag "" in your template(regardless of "short_open_tag"), so comes a option named "short_tag", you can switch this off to prevent use short_tag in template.

Exceptions

TypeError

__isset(string $name)

No description

Parameters

string $name

bool assign(string|array $name, mixed $value = null)

assign variable to view engine

Parameters

string|array $name
mixed $value

Return Value

bool

string render(string $tpl, array $tpl_vars = null)

No description

Parameters

string $tpl
array $tpl_vars

Return Value

string

Exceptions

View

bool display(string $tpl, array $tpl_vars = null)

Render a template and display the result instantly.

Parameters

string $tpl
array $tpl_vars

Return Value

bool

Exceptions

View

Simple assignRef(string $name, mixed $value)

unlike \Yaf\View\Simple::assign(), this method assign a ref value to engine.

Parameters

string $name

A string name which will be used to access the value in the template.

mixed $value

mixed value

Return Value

Simple

Simple clear(string $name = null)

clear assigned variable

Parameters

string $name

assigned variable name.
if empty, will clear all assigned variables.

Return Value

Simple

setScriptPath(string $template_dir)

No description

Parameters

string $template_dir

An absolute path to the template directory, by default, \Yaf\Dispatcher use application.directory . "/views" as this parameter.

string getScriptPath()

No description

Return Value

string

mixed __get(null $name = null)

Retrieve assigned variable


Note:

$name parameter can be empty since 2.1.11

Parameters

null $name

the assigned variable name


if this is empty, all assigned variables will be returned

Return Value

mixed

__set(string $name, mixed $value = null)

This is a alternative and easier way to \Yaf\View\Simple::assign().

Parameters

string $name

A string value name.

mixed $value

mixed value

void|bool eval(string $tpl_str, array $vars = null)

Render a string template and return the result.

Parameters

string $tpl_str
array $vars

Return Value

void|bool