ViewFish Basics

Use the source tab below to compare the rendered template to the source to use how you can use ViewFish Templating.

A test of ViewFish Templating


This is a test of ViewFish Templating. It was written by Adam Scheinberg. It is written in PHP.

The current date is July 19, 2024, which is often written as 2024-07-19 and corresponds to unix timestamp 1721355385, which can also be expressed as 1721355385. You can use arguments found at

It has basic skills, such as escaping text: <i><b>This should be escaped text</b></i>

It supports simple string functions, such as str_rot13 - IvrjSvfu Grzcyngvat - and juggling case - viewfish templating.

It supports custom functions: "Viewfish Templating-VIEWFISH TEMPLATING".

It also can chain functions, such as uppercasing and str_rot13: IVRJSVFU GRZCYNGVAT.

Here is a function that was dynamically added, sha1: 882d0edf97c3d20bdb3547dc7f9a68f62f99fe03

Here are example of a dynamic placeholders 1) a unique identifier: 6699cc79a19d7 2) a datetime: 2024-07-19 2:16:25 and 3) a datetime in UTC: 2024-07-19 2:16:25.

You can use substr, here's substr($str,3,10): quick bro. A long string can be quickly shortened using the shortcut function ellipsis: The quick brown fo…

Variables that end with an exclamation point will be removed if they are not matched - for example, it should be blank between the quotes "". But those unmatched will remain untouched, like {{so}}.


# require the templating library 
require '../source/ViewFish.php'

# first, you instantiate a ViewFish object
$T = new ViewFish\viewfish();

# set the template path

# You can feed the Small Axe object a memcached resource for storing uncompiled templates
# a memory cache system is optional
$memcache = new Memcached();

# you can also add functions that the template can parse
# currently, functions are only supported if they can take the value as an argument and return it as a string
# only functions YOU explicitly allow will work in your templates
# for example, this will add the "sha1()" and "str_rot13" functions  

# the extend() method will also accept your custom functions
function custom_function($string) { 

# define our variables
$vars = [
'software_title'     => "ViewFish Templating",
"author"              => "adam scheinberg"
'year'                  => date('Y'),
'language'             => "php",
'test_text'             => "<i><b>This should be escaped text</b></i>",
'random'            => "This is a random string",
'longstring'        => "The quick brown fox jumped over the lazy dog"

# load template by passing either the file in the templates folder OR a hard coded path 
# when searching the template directory, if no file extension is provided and no file is matched without an extension, 
# it will assume ".tmpl" or ".tpl"
$template     $T->load_template("demo1");

# compile the template 
$html         $T->render($template,$vars); 

# echo the template 
echo $html
        <title>A test of {{software_title|ucwords}}</title>
        <h1>WELCOME TO {{software_title|upper}}</h1>
        <p>This is a test of {{software_title}}.  It was written by {{author|ucwords}}. It is written in {{language|upper}}.</p>
        <p>The current date is {{date|F d, Y}}, which is often written as {{date|Y-m-d}} and corresponds to unix timestamp {{date|U}}, which can also be expressed as [[timestamp]]. You can use arguments found at <a href=""></a>.</p>
        <p>It has basic skills, such as escaping text: <code>{{test_text|e}}</code></p>
        <p>It supports simple string functions, such as str_rot13 - {{software_title|str_rot13}} - and juggling case - {{software_title|lower}}. </p>
        {* this is a Smarty style comment *}
        <p>It supports custom functions: {{software_title|custom_function}}. </p>
        C style 
        comment */
        <p>It also can chain functions, such as uppercasing and str_rot13: {{software_title|upper|str_rot13}}. </p>
        <p>Here is a function that was dynamically added, sha1: {{random|sha1}}</p>
        <p>Here are example of a dynamic placeholders 1) a unique identifier: [[uniqid]] 2) a datetime: [[datetime]] and 3) a datetime in UTC: [[utcdatetime]].</p>
        <p>You can use <b>substr</b>, here's substr($str,3,10): <i>{{longstring|substr:3:10}}</i>. A long string can be quickly shortened using the shortcut function <b>ellipsis</b>: <i>{{longstring|ellipsis:18}}</i></p>
        <p>Variables that end with an exclamation point will be removed if they are not matched - for example, it should be blank between the quotes "{{test!}}". But those unmatched will remain untouched, like {{so}}. </p>