ViewFish PHP Templating Engine
Configuration Options
You can pass an optional $options array when instantiating the ViewFish object to configure its behavior:
$options = [
'replace_empty' => true,
'cache_compiled' => false,
'memcached' => $memcachedObject,
'ttl' => 3600,
];
$t = new ViewFish\viewfish($options);
Available Options
| Option | Type | Default | Description |
|---|---|---|---|
replace_empty |
bool | false |
Strip unmatched {{variables}} from rendered output |
cache_compiled |
bool | false |
Cache templates after rendering (use with caution) |
memcached |
object | null |
A Memcached/Memcache object for template caching |
ttl |
int | 0 |
Cache lifetime in seconds (ignored without memcached) |
replace_empty
When set to true, any {{variable}} that doesn't match a key in your data array will be removed from the final output. Without this, unmatched placeholders remain visible.
$t = new ViewFish\viewfish(['replace_empty' => true]);
This is useful in production when you don't want raw template syntax leaking into your HTML. During development, leaving it off helps you spot missing data.
Note: You can also strip individual variables by appending ! — e.g. {{variable!}} will be removed if unmatched, regardless of this setting.
cache_compiled
When set to true, rendered templates are cached after compilation.
Warning: If your template contains user-specific data (names, emails, personalized content), the cached version will be served to the next visitor. Only use this for templates with static or shared content.
memcached
Pass a valid Memcached or Memcache object to enable in-memory caching of uncompiled templates. This reduces filesystem reads on subsequent calls.
$mc = new Memcached();
$mc->addServer('localhost', 11211);
$t = new ViewFish\viewfish(['memcached' => $mc, 'ttl' => 86400]);
ttl
Time-to-live for cached data, in seconds. Only applies when a memcached object is provided. Common values:
300— 5 minutes (good for frequently changing templates)86400— 1 day2592000— 30 days (good for templates that rarely change)