Developers

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 later on to PHP and saved to the /system/cache/ 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

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

Set a variable

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

If Statement

Conditional if statement

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

Elseif

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

Else

@else
<?php else: ?>

Endif

@endif
<?php endif: ?>

The various conditions that can be used

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

Foreach

Foreach loop

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

Ending the foreach

@endforeach
<?php endforeach; ?>

Counter

Starting a counter

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

Increasing the counter

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

Loading Templates

Loading a template

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

Comments

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 {{ comment.name }}
  @endif
  @increase count
@endforeach
<?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; ?>