# final class \SmartMarkersTemplating
{ } ::

Class: SmartMarkersTemplating - provides a very fast and low footprint templating system: Marker-TPL

- Language: PHP
- Located at: lib/framework/lib_templating.php
- Package: @Core:TemplatingEngine
- Namespace: \
- Class Name: SmartMarkersTemplating
- Version: v.20231228
- Depends: classes: Smart, SmartHashCrypto, SmartEnvironment, SmartUnicode, SmartFileSysUtils ; constants: SMART_FRAMEWORK_ERR_PCRE_SETTINGS, SMART_SOFTWARE_MKTPL_DEBUG_LEN (optional)
- Usage: static object: Class::method() - This class provides only STATIC methods

## class Methods

public static function analyze_debug_template ( string $mtemplate ) {} :: STRING
@return: {STRING} The analyze info HTML+JS
@param: {STRING} $mtemplate: The Marker-TPL string
Analyze a Marker Template String (NO Sub-Templates are loaded)
This is intended for DEVELOPMENT / DEBUG ONLY (never use this in production environments !)
public static function render_placeholder_tpl ( string $ptemplate, array $y_arr_vars, string $y_ignore_if_empty = "no" ) {} :: STRING
@return: {STRING} The parsed template
@param: {STRING} $ptemplate: The Placeholder-TPL string (partial text/html + placeholders) ; Ex: '<span>[:::PLACEHOLDER:::], ...</span>'
@param: {ARRAY} $y_arr_vars: The associative array with the template variables ; mapping the array keys to template placeholders is case insensitive ; Ex: [ 'PLACEHOLDER1' => 'Value1', 'placeholder2' => 'Value2', ..., 'PlaceholderN' => 100 ]
@param: {ENUM} $y_ignore_if_empty: 'yes' will ignore if Placeholder-TPL is empty ; 'no' will add a warning (default)
Render Placeholder Template (String Template ; no marker syntax is parsed ; only placeholders are strict replaced
This method adds a new feature to the Marker-TPL Templating system to allow add post-render variable areas to an already rendered Marker-TPL ; for example, a rendered Marker-TPL can be exported to cache but some areas perhaps need to be changed later so those areas can be replaced later by using placeholders
public static function render_template ( string $mtemplate, array $y_arr_vars, string $y_ignore_if_empty = "no" ) {} :: STRING
@return: {STRING} The parsed template
@param: {STRING} $mtemplate: The Marker-TPL string (partial text/html + markers) ; Ex: '<span>[###MARKER1###]<br>[###MARKER2###], ...</span>'
@param: {ARRAY} $y_arr_vars: The associative array with the template variables ; mapping the array keys to template markers is case insensitive ; Ex: [ 'MARKER1' => 'Value1', 'marker2' => 'Value2', ..., 'MarkerN' => 100 ]
@param: {ENUM} $y_ignore_if_empty: 'yes' will ignore if Marker-TPL is empty ; 'no' will add a warning (default)
Render Marker Template (String Template ; no sub-templates are allowed as there is no possibility to set a relative path from where to get them)
See the escapings and transformation at: Render Marker File Template
public static function render_file_template ( string $y_file_path, array $y_arr_vars, string $y_use_caching = "yes" ) {} :: STRING
@return: {STRING} The parsed and rendered template
@param: {STRING} $y_file_path: The relative path to the file Marker-TPL (partial text/html + markers + *sub-templates*) ; if sub-templates are used, they will use the base path from this (main template) file ; Ex: views/my-template.inc.htm ; (partial text/html + markers) ; Ex (file content): '<span>[###MARKER1###]<br>[###MARKER2###], ...</span>'
@param: {ARRAY} $y_arr_vars: The associative array with the template variables ; mapping the array keys to template markers is case insensitive ; Ex: [ 'MARKER1' => 'Value1', 'marker2' => 'Value2', ..., 'MarkerN' => 100 ]
@param: {ENUM} $y_use_caching: 'yes' will cache the template (incl. sub-templates if any) into memory to avoid re-read them from file system (to be used if a template is used more than once per execution) ; 'no' means no caching is used ; default is YES
Render Marker File Template (incl. Sub-Templates from Files if any)

    Sample code: PHP
    <?php

     // [###MARKER###]											:: marker with no escapes
     // [###MARKER|{escapes}] 									:: marker with escapes (one or many of): |bool |int |dec[1-4]{1} |num |date |datetime |datetimez |htmid |jsvar |stdvar |nobackslash |rxpattern |emptye |emptyna |idtxt |slug |substr[0-9]{1,5} |subtxt[0-9]{1,5} |lower |upper |ucfirst |ucwords |trim |url |json |jsonpretty |js |html |xml |css |nl2br |striptags |syntaxhtml |hex |hexi10 |b64 |b64s |b64tob64s |b64stob64 |b32 |b36 |b58 |b62 |b85 |b92 |crc32b |crc32b36 |md5 |md5b64 |sha1 |sha1b64 |sha224 |sha224b64 |sha256 |sha256b64 |sha384 |sha384b64 |sha512 |sha512b64 |sh3a224 |sh3a224b64 |sh3a256 |sh3a256b64 |sh3a384 |sh3a384b64 |sh3a512 |sh3a512b64
     // [@@@SUB-TEMPLATE:path/to/tpl.htm@@@] 				:: sub-template with relative path to template
     // [@@@SUB-TEMPLATE:?path/to/tpl.htm@@@] 				:: sub-template with relative path to template, optional, if exists
     // [@@@SUB-TEMPLATE:!etc/path/to/tpl.htm!@@@] 		:: sub-template with relative path to framework, using exact this path
     // [@@@SUB-TEMPLATE:?!if-exists/path/to/tpl.htm!@@@] 	:: sub-template with relative path to framework, using exact this path, optional, if exists
     // [@@@SUB-TEMPLATE:{tpl}|{escape}@@@] 				:: sub-template (using any kind of path from above), apply escape (any of): |syntax |syntaxhtml |html |xml |js |js-tpl-encode |tpl-uri-encode |tpl-b64-encode
     // [@@@SUB-TEMPLATE:%variable%@@@] 					:: variable sub-template ; must be defined in $y_arr_vars['@SUB-TEMPLATES@'] array as key (variable) => value (path)
     // [%%%IF:TEST-VARIABLE:@==|@!=|@<=|@<|@>=|@>|==|!=|<=|<|>=|>|!%|%|!?|?|^~|^*|&~|&*|$~|$*{string/number/a|list|with|elements/###MARKER###};%%%] conditional IF part, display when condition is matched [%%%ELSE:TEST-VARIABLE%%%] conditional ELSE part, display otherwise (optional) [%%%/IF:TEST-VARIABLE%%%]
     // [%%%LOOP:ARR-VARIABLE%%%] [###ARR-VARIABLE.ID|int###]. [###ARR-VARIABLE.NAME|html###] [%%%/LOOP:ARR-VARIABLE%%%]
     // [%%%COMMENT%%%] This is a comment in template that will not be displayed [%%%/COMMENT%%%]
     // And some special characters:
     //		[%%%|SB-L%%%] ensures a LEFT SQUARE BRACKET [
     //		[%%%|SB-R%%%] ensures a RIGHT SQUARE BRACKET ]
     //		[%%%|SPACE%%%] ensures a SPACE
     //		[%%%|T%%%] ensures a TAB \t
     //		[%%%|N%%%] ensures a LINE FEED \n
     //		[%%%|R%%%] ensures a CARRIAGE RETURN \r

     SmartMarkersTemplating::render_file_template(
     		'views/my-template.mtpl.htm',
     		[
     			'MARKER' 				=> 'something ...',
     			'TEST-VARIABLE' 		=> 'another thing !',
     			'ARR-VARIABLE' 		=> [
     				[ 'id' => 1, 'name' => 'One' ],
     				[ 'id' => 2, 'name' => 'Two' ],
     				[ 'id' => 3, 'name' => 'Three' ]
     			]
     		]
     );

    // #end php code

## class Properties

## class Constants

documentation generated on: 2024-12-16 16:53:45 +0000

Smart.Framework © 2009-2024 unix-world.org