Creating a new Template Variable
Creating a new Template Variable
Template Variables can be injected to TypoTonic fluid templates. You can select them in the Records-Plugin and later in many more plugins. The Template Variables can help you improve functionality of your displayed data by using them as filters, search, sortings or as modifiers. With help of the dynamic data, that is processed, when variables are injected, it is possible to add different functions to your view instead of just displaying data.
Configuration
Type¶Determines the type of the value. It can be dynamic or fixed. Please see the following options with their description.
Option NameDescriptionFixed ValueA fixed text valueTypoScript ValueParsed TypoScript valueGET VariableValue from the GET Parameters of the pagePOST VariableValue from the POST Parameters of the pageDatabase ValueDatabase Result Value from a given queryFrontend UserThe current frontend userServer VariableA variable from the SERVER ($_SERVER)User Session VariableExtracts a variable from the frontend user sessionPageAdds the complete page information of the selected page to the variableUserFuncCalls the entered user function and puts the output to the variableBackend UserAdds the current logged in backend user to the frontend template. If no user is logged in, it contains <span class="pre">null</span>Language IdAdds the current language id to the templateTypoTonic Session Service ContainerAdds the TypoTonic Session Service Container to the template, which contains all the filters, searches and moreName¶The variable name that can be used in the fluid template.
Use cases
- Inject dynamic values like the current date
- Inject back- or list page Ids to link to other pages without hardcoding ids
- Add custom PHP Script Values to the output by using TypoScript and USERFUNC
- Inject the current record on a site when using multiple plugins
- Provide different content by using conditions for variables
- Use variables to combine with filters of the records plugin
GET/POST Variables
GET/POST Variables have a different set of options for defining specific data, when variables are injected to the view.
Type Definition¶The variable can be set for a specific type, so you can prevent injection of malicious code.
Regular Expression¶Same like Type Definition, it is possible to set a regular expression to prevent unwanted injections.
Allowed Values¶Variable values can be predefined, so it is now possible to change the values to other content than defined.
Value Switch¶The Value Switch is a highly customizable way to change the value of the variable, before it is injected into the template. With the Value Switch, the data can be changed with the use of fluid. Each Value Switch has a condition (also written in fluid), which activates the switch, when the condition matches.
See the following example for a switch to create a sort order link with the opposite order, as given in the parameters:


