PHP-TAL
A combination of PHP TAL and replacement variables is used for template development.
What PHP-TAL is and how it is used can be found in the official TAL documentation:https://phptal.org/manuals.html
In particular, familiarize yourself with the following chapter:
- Attribute order
- tal:define
- tal:condition
- tal:repeat
- tal:omit day
- tal:replace
- tal:content
- tal:attributes
- string:
- not:
- exists:
- structure
- Expression chains
Basic information
only check then use
When working with fields, whether from the profile or articles, it is important to remember that this field may be empty or not exist at all.
There are several ways to do this:
- "has" functionsThe
TAL-API offers a number of functions that check if a value is set
.<div tal:condition="THIS/hasSlots/0">{$SLOT_0}</div>
<div tal:condition="THIS/hasAttribute/HEADLINE" tal:content="THIS/getAttributeByName/HEADLINE"> </div>
- exists
:The TAL modifier "exists:" checks if the given path exists but not if the value is empty
.<div tal:condition="exists: THIS/getCurrentUser/getValues/NOTE" tal:content="THIS/getCurrentUser/getValues/NOTE"> </div>
- equals
:The TAL modifier "equals:" can also be used to check if a value is empty by leaving the compare string empty. This is especially useful for profiles/pool fields.
<div tal:condition="not:equals:string:${THIS/getCurrentUser/getValues/FIRSTNAME}/">Hello ${THIS/getCurrentUser/getValues/FIRSTNAME}</div>
- Expression chains
:With "|" expression chains can be formed in TAL. Different expressions are evaluated from front to back and the first one that does not return NULL and no error is used. This makes it very easy to create a fallback for a value.
<h1 tal:content="THIS/getAttributeByName/HEADLINE|string:Please fill in heading"> </h1>
Avoid shorthand spelling
For some article attributes short spellings are available. These functions do not access a field directly, but access a field with a specific role:
<h1 tal:content="THIS/getHeadline"> </h1>
In this example, a field of the article is output with the role "Headline". This need not be the field "Headline". In addition, the role assignment can be changed later, which means that a different field is also output in the templates.
Better is getAttributeByName:
<h1 tal:content="THIS/getAttributeByName/HEADLINE"> </h1>
Shorthand methods are also available for accessing the slots of an e-mailing or lead page. These do not have any dependencies on a role model, but only support the first 10 slots.
<div tal:condition="THIS/hasSlot9">{$SLOT_9}</div>
Better:
<div tal:condition="THIS/hasSlots/10">{$SLOT_10}</div>
Check dummy user
If you want to access profile attributes or pool fields of the current profile, you should consider the case that there is no identified profile. This is the case in the preview or the visual editor, for example. In these cases getCurrentUser returns the profile of the dummy user.
Only some standard attributes are set for this user. Individual pool fields cannot be addressed.
To check if the current profile is the dummy user, use isDummy
<span tal:omit-tag="true" tal:condition="not:THIS/getCurrentUser/isDummy">{$INDIVIDUAL_SALUTATION}</span> <span tal:omit-tag=
"true" tal:condition="THIS/getCurrentUser/isDummy">Ladies and Gentlemen</span>