class vB_Template

This class implements variable-registration-based template evaluation, wrapped around the legacy template format. It will be extended in the future to support the new format/syntax without requiring changes to code written with it.

Currently these vars are automatically registered: $vbphrase $show, $bbuserinfo, $session, $vboptions

Properties

static protected array $pre_registered Preregistered variables.
static protected $placeHolders
protected string $template Name of the template to render
protected array $registered Array of registered variables.
protected bool $registered_globals Whether the globally accessible vars have been registered.
static array $template_usage Debug helper to count how many times a template was used on a page.
static array $template_queries Debug helper to list the templates that were fetched out of the database (not cached properly).

Methods

static vB_Template
create($template_name, $forcenoapi = false)

Factory method to create the template object.

static 
remove_common_show($show)

Unset common items in $show array for API

__construct($template_name)

vB_Template constructor.

string
get_template_name()

Returns the name of the template that will be rendered.

static 
preRegister(string $template_name, array $variables = NULL)

Preregisters variables before template instantiation.

bool
register(string $name, mixed $value, bool $overwrite = true)

Register a variable with the template.

quickRegister($values, $overwrite = true)

Registers an array of variables with the template.

register_global(string $name, bool $overwrite = true)

Registers a named global variable with the template.

bool
register_ref(string $name, mixed $value, bool $overwrite = true)

Registers a reference to a variable.

mixed
unregister(string $name)

Unregisters a previously registered variable.

bool
is_registered(string $name)

Determines if a named variable is registered.

mixed
registered(string $name = '')

Return the value of a registered variable or all registered values If no variable name is specified then all variables are returned.

register_page_templates()

Automatically register the page-level templates footer, header, and headinclude based on their global values.

register_globals(bool $final_render = false)

Register globally accessible vars.

string
render($suppress_html_comments = false, $final_render = false, $nopermissioncheck = false)

Renders the template.

string
render_output($suppress_html_comments = false, $nopermissioncheck = false)

Renders the output after preperation.

string
fetch_css_path()

Returns the CSS path needed for the {vb:cssfile} template tag

static string
fetch_template_raw(string $template_name)

Returns a single template from the templatecache or the database and returns the raw contents of it. Note that text will be escaped for eval'ing.

Details

at line 1100
static vB_Template create($template_name, $forcenoapi = false)

Factory method to create the template object.

Will choose the correct template type based on the request. Any preregistered variables are also registered and cleared from the preregister cache.

Parameters

$template_name
$forcenoapi

Return Value

vB_Template Template object

at line 1147
static protected remove_common_show($show)

Unset common items in $show array for API

Parameters

$show

at line 1169
protected __construct($template_name)

vB_Template constructor.

Protected constructor to enforce the factory pattern. Ensures the chrome templates have been processed.

Parameters

$template_name

at line 1179
string get_template_name()

Returns the name of the template that will be rendered.

Return Value

string

at line 1190
static preRegister(string $template_name, array $variables = NULL)

Preregisters variables before template instantiation.

Parameters

string $template_name The name of the template to register for
array $variables The variables to register

at line 1211
bool register(string $name, mixed $value, bool $overwrite = true)

Register a variable with the template.

Parameters

string $name Name of the variable to be registered
mixed $value Value to be registered. This may be a scalar or an array.
bool $overwrite Whether to overwrite existing vars

Return Value

bool Whether the var was registered

at line 1228
quickRegister($values, $overwrite = true)

Registers an array of variables with the template.

Parameters

$values
$overwrite

at line 1247
register_global(string $name, bool $overwrite = true)

Registers a named global variable with the template.

Parameters

string $name The global to register
bool $overwrite Whether to overwrite on a name collision

at line 1265
bool register_ref(string $name, mixed $value, bool $overwrite = true)

Registers a reference to a variable.

Parameters

string $name Name of the variable to be registered
mixed $value Value to be registered. This may be a scalar or an array
bool $overwrite Whether to overwrite existing vars

Return Value

bool Whether the var was registered

at line 1283
mixed unregister(string $name)

Unregisters a previously registered variable.

Parameters

string $name Name of variable to be unregistered

Return Value

mixed Null if the variable wasn't registered, otherwise the value of the variable

at line 1303
bool is_registered(string $name)

Determines if a named variable is registered.

Parameters

string $name Name of variable to check

Return Value

bool

at line 1315
mixed registered(string $name = '')

Return the value of a registered variable or all registered values If no variable name is specified then all variables are returned.

Parameters

string $name The name of the variable to get the value for.

Return Value

mixed If a name is specified, the value of the variable or null if it doesn't exist.

at line 1331
register_page_templates()

Automatically register the page-level templates footer, header, and headinclude based on their global values.

at line 1350
protected register_globals(bool $final_render = false)

Register globally accessible vars.

Parameters

bool $final_render
  • Whether we are rendering the final response

at line 1391
string render($suppress_html_comments = false, $final_render = false, $nopermissioncheck = false)

Renders the template.

Parameters

$suppress_html_comments
$final_render
$nopermissioncheck

Return Value

string Rendered version of the template

at line 1418
protected string render_output($suppress_html_comments = false, $nopermissioncheck = false)

Renders the output after preperation.

Parameters

$suppress_html_comments
$nopermissioncheck

Return Value

string

See also

vB_Template::render

at line 1464
string fetch_css_path()

Returns the CSS path needed for the {vb:cssfile} template tag

Return Value

string CSS path

at line 1518
static string fetch_template_raw(string $template_name)

Returns a single template from the templatecache or the database and returns the raw contents of it. Note that text will be escaped for eval'ing.

Parameters

string $template_name Name of template to be fetched

Return Value

string