As we saw above, there are placeholders that perform different functions. Panel placeholders start with the word Panel and snippets start with the word Snippet. There are other types of placeholders available:
- Panel - Indicates a placeholder for a panel file e.g.. %%Panel.PageHeader%%
- Config - Indicates a placeholder for text that is contained in the application's configuration file, which can be edited from the settings page in the control panel. E.g.. %%Config.WebsiteDescription%%
- LNG (Language) - Language placeholders display text from the language files located inside the application/includes/language folder. E.g.. %%LNG_NewAuthorIntro%%
- GLOBAL - Global data is set on the server side using PHP.
Generally the variable for a global placeholder is set by the
corresponding PHP file for the panel located inside the
application/includes/display folder. These placeholders generally do
not need to be modified unless you are an advanced user with PHP
skills. This contains data that needs to be calculated dynamically,
such as the article content, title, date and author. Eg.
%%GLOBAL_AuthorName%%
If you wanted to change how a particular global variable is set, then you can modify the PHP file that matches the same name as the panel file it is being used in. For example, you can modify the %%GLOBAL_Title%% variable, which is used inside the ViewArticlePanel.html (used to display the title of the article) from the application/includes/display/ViewArticlePanel.php file.
The variable name being set inside the PHP file would match the name of the global placeholder. For our above example, it would be: $GLOBALS['Title'] so you can search for $GLOBALS['Title'] = 'example'; to locate where the variable is being set.
Creating Placeholders
There are two placeholder variable types that can be created very easily: language
(LNG) and global (GLOBAL) placeholders.
Snippets are also placeholders, but they require more PHP modification.
Creating Language Placeholders
To create a language variable, you will need to add a new entry to the front end language file. The language files are located in the /includes/language/ folder. If you are creating an entry for your front website template, edit the front_language.ini file. If you are making a placeholder to be used in the control panel, then use the back_language.ini file. Here is the format for a language variable:
MyVariable = "My text"
You will then be able to use this following placeholder in your template:
%%LNG_MyVariable%%
and it will output:
My Text
in its place. Note: As your text is wrapped in double quotes " it is best to avoid these in your text as using it will cause the language variable to not work. If you need to use double quotes for any reason, use the HTML entity: " For example, say you wanted: My "Text" here, you would use:
MyVariable = "My "Text" here"
Creating Global Placeholders
Global placeholders are usually created in the PHP panel files. These are located at /includes/display/. A global is set in a line of code like this:
$GLOBALS['MyVariable'] = "My Text";
You will then be able to use this following placeholder in your template (Notice the 'S' is gone from GLOBALS):
%%GLOBAL_MyVariable%%
and it will output:
My Text
However, globals will often not just be placeholders for plain text
written into the PHP. Global placeholders will have dynamic content loaded,
often from the database.
Creating Snippets
Snippets need to be declared in a PHP file such as a Panel PHP file which are located in the /includes/display/ folder.
$GLOBALS['SNIPPETS']["Example"] = $GLOBALS["AL_CLASS_TEMPLATE"]->GetSnippet("ExampleSnippet");
This allows the use of this following placeholder in a Panel or Layout file:
%%SNIPPET_Example%%
Which will print out the contents of /templates/{your-template}/Panels/Snippets/ExampleSnippet.html
