.. include:: ../../Includes.txt .. _variable_gs: .. image:: ../../Images/logo_typotonic.jpg :width: 250px 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. .. image:: ../../Images/Screenshots/GetStarted/new_variable.jpg :width: 200px | Configuration ~~~~~~~~~~~~~ .. confval:: Type Determines the type of the value. It can be dynamic or fixed. Please see the following options with their description. +-----------------------+-------------------------------------------------------------+ | Option Name | Description | +=======================+=============================================================+ | Fixed Value | A fixed text value | +-----------------------+-------------------------------------------------------------+ | TypoScript Value | Parsed TypoScript value | +-----------------------+-------------------------------------------------------------+ | GET Variable | Value from the GET Parameters of the page | +-----------------------+-------------------------------------------------------------+ | POST Variable | Value from the POST Parameters of the page | +-----------------------+-------------------------------------------------------------+ | Database Value | Database Result Value from a given query | +-----------------------+-------------------------------------------------------------+ | Frontend User | The current frontend user | +-----------------------+-------------------------------------------------------------+ | Server Variable | A variable from the SERVER ($_SERVER) | +-----------------------+-------------------------------------------------------------+ | User Session Variable | Extracts a variable from the frontend user session | +-----------------------+-------------------------------------------------------------+ | Page | Adds the complete page information of the selected page | | | to the variable | +-----------------------+-------------------------------------------------------------+ | UserFunc | Calls the entered user function and puts the output to | | | the variable | +-----------------------+-------------------------------------------------------------+ | Backend User | Adds the current logged in backend user to the frontend | | | template. If no user is logged in, it contains ``null`` | +-----------------------+-------------------------------------------------------------+ | Language Id | Adds the current language id to the template | +-----------------------+-------------------------------------------------------------+ | TypoTonic Session | Adds the TypoTonic Session Service Container to the | | Service Container | template, which contains all the filters, searches and more | +-----------------------+-------------------------------------------------------------+ .. confval:: Name 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. .. confval:: Type Definition The variable can be set for a specific type, so you can prevent injection of malicious code. .. confval:: Regular Expression Same like Type Definition, it is possible to set a regular expression to prevent unwanted injections. .. confval:: Allowed Values Variable values can be predefined, so it is now possible to change the values to other content than defined. .. confval:: 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: .. image:: ../../Images/Screenshots/GetStarted/screenshot_value_switch.jpg