Common template mistakes
This page is for designers who want to avoid the usual traps. Each mistake has a symptom, so you can also use the page to find the cause of a problem.
Contents
Output and security
| Mistake | Symptom | Fix |
|---|---|---|
printing a value without |wash | HTML from content breaks the page; script injection possible | wash at output (Wash and escaping) |
| washing rich text output | tags shown as text | do not wash attribute_view_gui output |
| washing twice | & on the page | wash once, at the end |
inline <script> or onclick | blocked under a Content Security Policy | script files (No inline JavaScript) |
Data and speed
| Mistake | Symptom | Fix |
|---|---|---|
a fetch inside a foreach | slow pages, many queries in the debug output | one fetch before the loop (Fetch performance) |
a list fetch without limit | very slow pages on big folders | always a limit, paginate |
reading $node.children for a menu | all children loaded with all data | a fetch with limit and class_filter_array |
| drawing an empty field | empty wrappers, stray labels | test has_content first |
Caching
| Mistake | Symptom | Fix |
|---|---|---|
| user data in a view-cached full view | one visitor sees another's name | move it to the pagelayout or vary the cache (Caching for designers) |
| a cache-block without the current page in its keys | the menu marks the wrong page | add $module_result.uri or the node id to keys |
csp_nonce() in cached output | scripts blocked on later visits | script files; nonce only outside caches |
currentdate() or rand() in cached output | date or random value frozen | compute it outside cached parts |
Syntax
| Mistake | Symptom | Fix |
|---|---|---|
quotes around ezurl: href="{$x|ezurl}" | href=""/path"" broken attribute | write href={$x|ezurl}, or ezurl( 'no' ) inside your quotes (URL operators) |
$a == $b | parse error | eq( $a, $b ) |
{def} of an existing variable | warning, includer's value overwritten | prefixes and {undef} (Variables and def) |
comparing strings with gt | unexpected results | gt compares lengths of non-numeric strings (Logic and comparison operators) |
| an operator from an inactive extension | "Operator '...' is not registered" in the debug output, nothing printed | activate the extension or use another operator |
Files and caches
| Mistake | Symptom | Fix |
|---|---|---|
editing a template in design/standard or a shipped theme | change lost on upgrade | copy it into your design (The design cascade) |
| a new template or override not showing | old template still used, or empty content area | clear template-override (Debugging a design) |
an override with a typo in MatchFile | rule ignored, error log entry | check the path under override/templates/ |
| two overrides for the same source | the wrong one wins | Priority (Override ordering) |
Related pages
- Template style guide
- Template debugging
- Free documentation: this page is free to copy, translate and improve under the GNU FDL 1.3.
Become an Exponential Partner
Partners share their information, provide funding, contribute back and develop the products with us, and that is how Exponential grows. A partner website and dashboard are planned for mid-2027: please become a partner today to speed up our growth rate and land new features faster.