Template Engine

Commentics uses a custom-made template engine, similar to Twig but lighter, while inspired by Blade.

What does it do? It allows for a shorter, more readable style of templating code to be written. Behind the scenes it's converted to PHP and saved to the /system/cache/template/ folder. Whenever you modify a template, Commentics will automatically parse it again. At all other times it loads it from the cache, meaning there's no loss in performance.

Also, you can still use plain PHP code if you prefer!


Echo a simple variable

    						{{ var }}
    						<?php echo $var; ?>

If the echo is within double quotes, any double quotes inside the variable will be handled.

    						title="{{ var }}"
    						title="<?php echo $this->variable->encodeDouble($var); ?>"

Echo the element of an array

    						{{ var.test }}
    						<?php echo $var['test']; ?>


Set a variable

    						@set reply_depth = 0
    						<?php $reply_depth = 0; ?>

If Statement

Conditional if statement

    						@if show_flag
    						<?php if ($show_flag): ?>


    						@elseif show_flag
    						<?php elseif ($show_flag): ?>


    						<?php else: ?>


    						<?php endif: ?>

The various conditions that can be used

    						equals becomes ==
    						not equal to becomes !=
    						more than becomes >
    						less than becomes <
    						and becomes &&
    						or becomes ||


Foreach loop

    						@foreach comments as comment
    						<?php foreach ($comments as $comment): ?>

Ending the foreach

    						<?php endforeach; ?>


Starting a counter

    						@start count at 1
    						<?php $count = 1; ?>

Increasing the counter

    						@increase count
    						<?php $count++; ?>

Decreasing the counter

    						@decrease count
    						<?php $count--; ?>

Loading Templates

Loading a template

    						@template main/comment
    						<?php require($this->loadTemplate('main/comment')); ?>


Comments are removed

    						{# This is a comment #}

Full Example

A full example of the above

    						@start count at 1
    						@foreach comments as comment
    						  @if count equals 2
    						      {# Display who posted the second comment #}
    						      The second comment is by {{ }}
    						  @increase count
    						<?php $count = 1; ?>
    						<?php foreach ($comments as $comment): ?>
    						  <?php if ($count == 2): ?>
    						    The second comment is by <?php echo $comment['name']; ?>
    						  <?php endif: ?>
    						  <?php $count++; ?>
    						<?php endforeach; ?>