Skip to content

Releases: Aleksandr-ru/TemplateObject

Forced filter

15 Jun 11:53
Compare
Choose a tag to compare

Forced filter mechanism is now applied instead of default filter for variables.

Forced filter is filter applied to a variable first, if no "raw" filter is set and no same filter presents.
By default forced filter is set to "html" and could be changed via new methods (getter and setter).
Forced filter can contain several elements like html|nl2br, each will be prepended to variable's filters, if is not set.

Example:

Before 2.7 {{VAR}} means {{VAR|html}} and {{VAR|js}} means only {{VAR|js}} (no html applied).

Now {{VAR}} means {{VAR|html}} and {{VAR|js}} means {{VAR|html|js}} (html is forcefully prepended).

To get back old behaviour of {{VAR|js}} you need to add "raw" filter like {{VAR|raw|js}}.

New mechanism may cause some backwards compatibility issues, but in most cases everything works as usual.

Composer support

02 Oct 13:42
Compare
Choose a tag to compare

TemplateObject now available via composer!

composer require aleksandr.ru/template-object

🎉️

More efficiency

10 Jun 13:55
Compare
Choose a tag to compare

This release removes old side effect of preserving blocks by setting it to non-assoc array with setVarArray function.
Example code, see comments for details:

$tpl->setVarArray([
	'multiblock1' => [ // ok, will be set twice with given variables from array
		['VAR1' => 'val1', 'VAR2' => 'val2'],
		['VAR1' => 'val3', 'VAR2' => 'val4'],
	],
	'multiblock2' => [true], // won't be preserved as empty block
	'multiblock3' => [0, 1, 2], // won't be preserved as empty block
	'multiblock4' => null, // only this will be preserved as empty block
]);

Template processing boost 🚀

04 Jun 09:33
Compare
Choose a tag to compare

New option public $debug = false to suppress user-level errors (warnings and notices). Effects when processing large amount of data, see here for performance issue.

Some minor fixes in setVarArray function logic.

Recursive blocks

05 Apr 12:32
Compare
Choose a tag to compare

Block recursion are here! But be careful using it.
Now you can add special markup to block to make it recursive.

<!-- RECURSION blockname -->

This placeholder will be replaced with entire block content and will be accessible inside the block with given 'blockname'.

So, for example, you can make a recursive lists:

<ul>
	<!-- BEGIN listitem -->
	<li>
		Item of level {{LEVEL}}
		<ul>
		<!-- RECURSION listitem -->
		</ul>
	</li>
	<!-- END listitem -->
</ul>

The recursion available with direct calls of setBlock or setVarArray with nested arrays, for example:

$a = array(
	'block' => array(
		'LEVEL' => 1,
		'block' => array(
			'LEVEL' => 2,
			'block' => array(
				'LEVEL' => 3,
			),
		),
	),	
);
$to->setVarArray($a);

Chaining also available like $to->setBlock('block')->setBlock('block')->setBlock('block');

Empty blocks

03 Apr 13:15
Compare
Choose a tag to compare

Now you can preserve empty blocks in setVarArray by setting
'emptyblock' => NULL
The block will be "touched" same as setBlock('emptyblock');

Block options

23 Aug 16:05
Compare
Choose a tag to compare

Now you can add option "rsort" to block markup to get this block output in reverse order. Example:

<!-- BEGIN myblock rsort -->
...
<!-- END myblock -->

More options will be available in further releases.

Also some minor bug fixes.

Introducing global variables

14 Jul 10:26
Compare
Choose a tag to compare

Now you can set a global variable to template and it will be automatically set in all newly created children blocks.
All global variables can be overlapped by setting local variables with the same name.

Extend template

22 Apr 12:49
Compare
Choose a tag to compare
Extend template Pre-release
Pre-release

Now templates can extend each other by replacing it's blocks with own content

Get variables and blocks

22 Apr 14:53
Compare
Choose a tag to compare

Ability to get variables and blocks from loaded template