Dynamic Files
This feature allows users to use template expressions or scripting in text files as it works in the page rendering engine.
There’s a boolean switch labeled Is Template. If activated, template expressions and scripts are evaluated at runtime.
In the integrated file editor, the switch is triggered by the checkbox labeled Replace template expressions:. Please make sure to have saved the content before activating the switch, and pay attentation to not overwrite the template expression by the evaluation result.
In the following example, we created a simple text file containing My path is: ${this.path}
. Depending on the location of the file in Structr’s virtual filesystem, it displays the file’s path dynamically.
If you move the file into a subdirectory, the text changes accordingly.
The expression/script evaluation does not depend from the way you access the file, so you also get the dynamic content when accessing the file over FTP or SSH/SCP.
Please note that you should use this feature with care. It is recommended to use it only with read-only file access as saving the evaluation result would overwrite the template expression or script.
Update: In versions after 2017-07-31 the content of the edit-mode window will always show the source code for admin users. Regular users will always get the evaluated version and will not be able to see the source code when the flag is set. Admin users can see the evaluated file by opening it in a new tab.
This means that there is no need for special caution when saving the contents of the file as the editor window will always display the source code.