XF 2.1 Guidance I thought I'd find in "Template syntax"

Neilski

Active member
Apologies if this is the wrong sub-forum for asking this...

I'm slowly getting to grips with XF2, having been pretty noobish with XF1 but just about able to accomplish what I needed.
While editing a template, I've discovered a few template syntax elements that aren't explained in the main doc page for templates: https://xenforo.com/xf2-docs/dev/template-syntax/

For example, if you have a number followed by "|file_size" it gets reformatted like a file size (e.g. "123.4 MB"). I've found through googling that this is known as a filter, but it's not defined in the syntax docs. Is it defined somewhere else instead?

At an even more basic level, I'm confused about when I should be using single braces and when it should be double braces ({{) - again, I'd expected to find guidance on this in the doc above but it's not there (too basic?); does this explanation exist anywhere?
 
For example, if you have a number followed by "|file_size" it gets reformatted like a file size (e.g. "123.4 MB"). I've found through googling that this is known as a filter, but it's not defined in the syntax docs. Is it defined somewhere else instead?
Unfortunately, the developer documentation is not comprehensive. A full list of filters (taken from src/XF/Template/Templater.php):
Code:
default
censor
count
currency
emoji
escape
for_attr
file_size
first
format
hex
host
htmlspecialchars
ip
join
json
last
nl2br
nl2nl
number
number_short
pad
parens
pluck
preescaped
raw
replace
split
split_long
strip_tags
to_lower
to_upper
de_camel
substr
url
urlencode
zerofill

At an even more basic level, I'm confused about when I should be using single braces and when it should be double braces ({{) - again, I'd expected to find guidance on this in the doc above but it's not there (too basic?); does this explanation exist anywhere?
Generally speaking, you can use single braces for echoing (including variables, read-only methods on objects, and filter application), and double braces for more complex expressions (ternaries, calculations, concatenations, etc).
 
Thanks for the tips Jeremy!
Unfortunately, the developer documentation is not comprehensive.
Yes, that was my experience under XF1 for sure but I had somehow got it in my head that XF2 had been approached differently (I guess I mean more docs, right from the off).
At least I feel better that I didn't just fail to find the docs... hehe :D (y)
 
Back
Top Bottom