XF 2.1 Can someone explain what the pipe symbol does?

| is a binary operator in PHP
Correct.

But that's not why it is used here.

It's used in templates to access a templater filter. A templater filter is used generally to translate a value. In this case we take a numerical value like {$thread.reply_count} and run it through our number filter. This filter is what turns a number like 1234 into a formatted string like 1,234 or 1.234.

for_attr is for escaping strings. It is specifically to escape strings used inside HTML attributes. Note, that is actual HTML attributes and not XF template tag attributes.

So if you have a string like Click -> "here" it is escaped to Click -> "here" in order to ensure that it isn't possible to break out of the attribute.
 
for_attr is for escaping strings. It is specifically to escape strings used inside HTML attributes. Note, that is actual HTML attributes and not XF template tag attributes.

So if you have a string like Click -> "here" it is escaped to Click -> "here" in order to ensure that it isn't possible to break out of the attribute.

Should we always use for_attr when creating data-xf-init tooltips?
 
You should use |for_attr whenever placing unescaped values (generally anything but string literals) in HTML attributes. In your case, if you're using a phrase or such in the title attribute for the tooltip, then yes.
 
Top Bottom