\apex\app\webview

Template Parser

Service: apex\utils\template

Handles the parsing of all .tpl template files located within the /views/ directory. For more information on templates, please refer to the developer documentation.

This class is available within the services container, meaning its methods can be accessed statically via the service singleton as shown below.

PHP Example

<?php

namespace apex;

use apex\app; use apex\utils\template;

view::assign('name', 'John Smith'); $html = view::parse();

Summary

Methods
Properties
Constants
__construct()
initialize()
parse()
parse_html()
load_base_variables()
parse_attr()
assign()
add_callout()
add_javascript()
has_errors()
get_title()
get_callouts()
reset()
No public properties found
No constants found
execute_php_file()
dispatch_rpc_call()
add_layout()
get_page_title()
process_page_title()
process_nav_menu()
process_menu_row()
process_function_tags()
process_if_tags()
process_sections()
process_theme_components()
cache_assets()
merge_vars()
add_system_javascript()
process_theme_page_function()
$template_path
$path_is_defined
$theme_dir
$has_errors
$callouts
$page_title
$vars
$js_code
$tpl_code
N/A
get_html_tag()
$app
$html_tags
N/A

Properties

$template_path

$template_path : 

Type

$path_is_defined

$path_is_defined : 

Type

$theme_dir

$theme_dir : 

Type

$has_errors

$has_errors : 

Type

$callouts

$callouts : 

Type

$page_title

$page_title : 

Type

$vars

$vars : 

Type

$js_code

$js_code : 

Type

$tpl_code

$tpl_code : 

Type

$app

$app : 

Type

$html_tags

$html_tags : 

Type

Methods

__construct()

__construct(\apex\app  $app, \apex\app\web\html_tags  $html_tags, string  $template_path = '') 

Constructor

Parameters

\apex\app $app

The main apex\app object

\apex\app\web\html_tags $html_tags

The html_tags object

string $template_path

The URI to display

initialize()

initialize() 

Initialize template engine

Initializes the template engine, and sets the appropriate route based on URI from registry.

parse()

parse() : string

Parse a TPL template file

Fully parses a template including all aspects from theme layouts, special tags, and more.

Returns

string —

THe resulting HTML code.

parse_html()

parse_html(string  $html) : string

Parse TPL code

Parses TPL code, and transforms it into HTML code. This is used for the body of the TPL file, but also other things such as the resulting TPL code from HTML functions and tab controls.

Parameters

string $html

The TPL code to parse.

Returns

string —

The resulting HTML code.

load_base_variables()

load_base_variables() 

Protected. Assign base variables

Assigns the base variables that are available to all templates, such as the URI to the theme directrory, the ID# of the auhenticated user, and so on.

parse_attr()

parse_attr(string  $string) : array

Get attributes of HTML tag

Simply parses the attributes of any given HTML tag, and returns them in an array.

Parameters

string $string

The string of text to process.

Returns

array —

The attributes contained within passed string.

assign()

assign(string  $name, mixed  $value) 

Assign variable

Assigns a variable which is then later replaced by the corresponding merge field within the TPL code. Merge fields are surrounded by tilda marks (eg. ~name~). ( Supports arrays as well, and values can be access via merge fields with ~arrayname.variable~

Parameters

string $name

The name of the merge variable.

mixed $value

The value of the merge variable -- string or array.

add_callout()

add_callout(string  $message, string  $type = 'success') 

Add callout message

Adds a callout message, which is then displayed at the top of the template

Parameters

string $message

The message to add

string $type

Optional type, defaults to 'success', but can also be either 'error' or 'info'

add_javascript()

add_javascript(string  $js) 

Add Javascript ( Adds Javascript, which is later included just above the </body> tag upon processing. Rarely used.

Parameters

string $js

The Javascript to add.

has_errors()

has_errors() : boolean

Check for user errors.

Returns a boolean whether or not the current template has any callouts of the 'error' type, meaning there are user generated errors.

Returns

boolean —

If callout errors exist

get_title()

get_title() : string

Get the page title

Returns

string —

The current page title

get_callouts()

get_callouts() : array

Get all callouts

Returns

array —

Array of all callouts currently added to the template.

reset()

reset() 

Reset, and get ready for another request.

execute_php_file()

execute_php_file() 

Parse .php file of a template.

dispatch_rpc_call()

dispatch_rpc_call() 

Dispatch RPL call, perform actions of other packages.

Dispatch an RPC call, and update template variables accordingly, depending on what other packages require.

add_layout()

add_layout() 

Add layout to TPL file

Overlays a TPL file with the appropriate layout, depending on the template being displayed, and which theme is being used.

get_page_title()

get_page_title() 

Get page title

Gets the page title. Checks the cms_templates mySQL table, and otherwise looks for a

...

tags in the TPL code, and if non exist, default to the $config['site_name'] variable.

process_page_title()

process_page_title(string  $html) : string

Process page title

Processes the page title, and adds it into the correct places within the template with the proper formatting.

Parameters

string $html

The HTML to replace title within.

Returns

string —

The resulting HTML

process_nav_menu()

process_nav_menu(string  $html) : string

Process nav menu

Parses the as necessary, and replaces with the appropriate HTML code. Please refer to documentation for full details.

Parameters

string $html

The HTML code to parse.

Returns

string —

The resulting HTML code.

process_menu_row()

process_menu_row(string  $html, array  $row, string  $submenus = '') : string

Protected. Process single nav menu row.

Protected function that processes a single row from the 'cms_menus' table, and returns the appropriate HTML for that single menu item.

Parameters

string $html

The HTML code to use for the menu.

array $row

The row from the 'cms-_menus' database table.

string $submenus

The HTML code for any sub menus.

Returns

string —

The resulting HTML code.

process_function_tags()

process_function_tags(string  $html) : string

Process function HTML tags

Processes all the tags within the TPL code, and replaces them

Parameters

string $html

The HTML code to process.

Returns

string —

The resulting HTML code.

process_if_tags()

process_if_tags(string  $html) : string

Process IF tags

Parses all the tags within the TPL code, and returns the appropriate HTML

Parameters

string $html

The HTML code to process.

Returns

string —

The resulting HTML code.

process_sections()

process_sections(string  $html) : string

Process section tags

Processes all the tags found within the TPL code, which loop over an array copying the HTML in between the tags for each set of data.

Parameters

string $html

The HTML code to process.

Returns

string —

The resulting HTML code.

process_theme_components()

process_theme_components() 

Process a:theme tags

Parses all the tags within the TPL code, and replaces them with the correct contents for the section within the THEME_DIR/sections/ directory.

cache_assets()

cache_assets() 

Load assets from cache

Goes through all javascript, CSS, and image references that point internally to the server, and either retrives them fromthe cachce, or adds them to the cache if the item doesn't already exist.

merge_vars()

merge_vars(string  $html) : string

Merge assigned variables

Goes through the self::$vars array, which is populated via the self::assign() method, and replaces all occurences of ~key~ with its corresponding value within the TPL code. Fully supports arrays with ~arrayname.key~ merge fields in the TPL code.

Parameters

string $html

The HTML code to process.

Returns

string —

The resulting HTML code.

add_system_javascript()

add_system_javascript(string  $html) 

( Replace TPL file with system Javascript

Add system Javascript

Parameters

string $html

The HTML code to process.

process_theme_page_function()

process_theme_page_function(string  $html) : string

Process process_page() function from theme.php file

Parameters

string $html

The current HTML code of the page

Returns

string —

The resulting HTML code

get_html_tag()

get_html_tag(string  $tag, array  $attr, string  $text = '') : string

Get HTML code for all <a:> tags

Retrives the correct HTML code for any other special e: tag. Generally goes through the /lib/html_tags.php class, unless a specific method exists for this theme.

Parameters

string $tag

The name of the HTML tag.

array $attr

The attributes specified within the HTML tag.

string $text

Any text in between opening and closing tags.

Returns

string —

The resulting HTML code.