Syntax Comparison

Side-by-side code comparisons: Tplix tag syntax vs PHP. See how Tplix reduces template syntax by up to 72%, eliminates delimiter confusion, and makes templates readable for designers and developers alike.

Template Syntax: Tplix vs PHP

PHP is powerful for application logic — but embedding its syntax directly into HTML creates noise, confusion, and fragile templates. Tplix replaces PHP statements with a clean, minimal tag-based syntax that anyone can read and maintain, no PHP knowledge required.

1

Displaying a Variable

PHP
<?=$foo?>
Tplix
{$foo}
PHP: 5 punctuation characters
Tplix: 2 punctuation characters
60% less syntax noise
2

Array Access

PHP
<?=$foo['bar']?>
Tplix
{$foo.bar}
PHP: 9 punctuation characters
Tplix: 3 punctuation characters
67% less syntax noise
3

Foreach Loop

PHP
<?php foreach($foo as $bar): ?> ... <?php endforeach; ?>
Tplix
{foreach $foo as $bar} ... {/foreach}
PHP: 18 punctuation characters
Tplix: 5 punctuation characters
72% less syntax noise
4

Real-World: Mixed With HTML Tags

Most telling example
PHP
<?php if(!empty($foo)): ?> <?php foreach($foo as $bar): ?> <a href="<?=$bar['zig']?>"><?=$bar['zag']?></a> <a href="<?=$bar['zig2']?>"><?=$bar['zag2']?></a> <a href="<?=$bar['zig3']?>"><?=$bar['zag3']?></a> <?php endforeach; ?> <?php else: ?> There were no rows found. <?php endif; ?>
Tplix
{foreach $foo as $bar} <a href="{$bar.zig}">{$bar.zag}</a> <a href="{$bar.zig2}">{$bar.zag2}</a> <a href="{$bar.zig3}">{$bar.zag3}</a> {foreachelse} There were no rows found. {/foreach}
110
characters saved
36%
syntax reduction
Tplix also handles boilerplate automatically — notice there's no need for an empty() check. Tplix's {foreachelse} handles it cleanly.

A note on PHP short-tags

The examples above use PHP short-tag syntax (<?=$foo?>) as a shortcut for <?php echo $foo; ?>. Many developers avoid short-tags entirely since they are optional and not guaranteed across all server configurations. Let's compare the full syntax instead:

PHP (long syntax)
<?php echo $foo; ?>
Tplix
{$foo}
13 character savings for a single variable
69% shorter
5

Long PHP Syntax Mixed With HTML

PHP
<a href="<?php echo $bar['zig']; ?>"><?php echo $bar['zag']; ?></a> <a href="<?php echo $bar['zig2']; ?>"><?php echo $bar['zag2']; ?></a> <a href="<?php echo $bar['zig3']; ?>"><?php echo $bar['zag3']; ?></a>
Tplix
<a href="{$bar.zig}">{$bar.zag}</a> <a href="{$bar.zig2}">{$bar.zag2}</a> <a href="{$bar.zig3}">{$bar.zag3}</a>

Delimiter Confusion

PHP tags share the < > characters of HTML tags. Mixed inside HTML markup, <?php ?> tags become genuinely difficult to distinguish from HTML elements at a glance — especially in a large template file. This blurs the boundary between application logic and presentation.

😵
Hard to Scan

<?php and <div> look nearly identical at a glance in a large template

🔓
Logic Can Leak In

Any PHP can be injected directly into templates — no boundary between logic and presentation

✅
Tplix {tags} Fix This

Curly-brace syntax is visually distinct from HTML — impossible to confuse with an HTML tag

Simplified Logic

Tplix features human-readable logic statements. The following examples show the difference side by side.

Printing odd numbers 1–20

PHP
<?php for($x=0; $x<20; $x+=2): ?> <?php echo $x+1; ?> <?php endfor; ?>
Tplix
{for $x = 1 to 20 step 2} {$x} {/for}

Table rows — new row every 4th item

Loops over $foo and starts a new table row after every 4th cell.

PHP
<?php $counter=0; ?> <?php foreach($foo as $bar): ?> <?php if(($counter+1) % 4 == 0): ?> </tr><tr> <?php endif; ?> <td><?php echo $bar; ?></td> <?php $counter++; ?> <?php endforeach; ?>
Tplix
{foreach $foo as $bar} {if $bar@iteration is div by 4} </tr><tr> {/if} <td>{$bar}</td> {/foreach}

Output modifiers — lowercase and HTML-escape a variable

Notice the natural left-to-right flow in Tplix — it reads like a sentence.

PHP
<?php echo htmlspecialchars(strtolower($foo),ENT_QUOTES,'UTF-8'); ?>
Tplix
{$foo|lower|escape}
Want to escape for JavaScript instead? One extra parameter:
Tplix
{$foo|lower|escape:javascript}

lower and escape are built-in plugins. They're purpose-built for presentation output — not general-purpose PHP functions. Chainable, readable, and designer-friendly.

Syntax at a glance

Task PHP chars Tplix chars Saving
Variable output 5 2 60%
Array access 9 3 67%
Foreach loop 18 5 72%
Real-world HTML block ~306 ~196 36%
Single echo (long syntax) 19 6 69%
See it in action

Browse the full syntax reference in the documentation and try it on your own templates.

View Syntax Docs →