Twig is fully documented with a dedicated online book and full API documentation. For more information see: https://twig.symfony.com/documentation
SupportPro ships with a default set of templates:
resources/templates/frontend/default
resources/templates/operator/default
For small template changes we highly recommend to investigate whether it's possible to use our plugin eco system. This appropriate is more beneficial than the following 2 methods because it means you no longer have to maintain the changes between SupportPro versions.
For example, below we're going to change the default selected Priority on the Submit Ticket page that's visible to users:
<script type="text/javascript">
var element = document.getElementById('priority');
if (element !== null) {
element.value = 1;
}
</script>
1
to the ID of the priority that you want to select.There are several other use cases that our possible so we encourage you to read through the Extending Templates plugin documentation.
If you're familiar with Git, we've made our templates available on Github (frontend-template and operator-template), allowing you to have your own fork and build your templates in a way that can be tracked and automatically updated when new versions of SupportPro are released.
$ git clone https://github.com/username/frontend-template.git
resources/templates/frontend
for example: resources/templates/frontend/custom_template
where custom_template
is the name of the new directory.resources/templates/frontend/custom_template
on your server.When a new version of SupportPro is released, our resources repository is updated and those changes should be merged in to your own repository and any conflicts dealt with. Check Github's syncing a fork guide for more information on how to do this.
Alternatively if you aren't familiar with Git, you can simply copy and edit the template manually. Copy the default template to a new folder with the name of your choice.
When a new version of SupportPro is released, we add a list of resource changes (example) to the release notes showing a diff of what has changed between releases. These changes should be copied in to your template to ensure it remains fully functional.
When working on your template, we recommend to keep the asset files (files under the resources/assets/
folder) the same, and instead create your own CSS or JS files that are loaded separately, making it easier to work with changes to assets files between releases.
We've made some of our helper functions available for use in templates, below are a few that you might find useful in your template changes.
If you need to display any user submitted content, it is best to purify the HTML to remove the risk of XSS. This can be done with the Purifier.clean
method.
{{ Purifier.clean(html_content) }}
Twig will automatically escape any HTML within a Twig tag. To stop this and display the code as it is, use the raw
filter. Be careful to only do this on safe HTML that doesn't contain user submitted content.
{{ html_content|raw }}
Creates a versioned URL for assets, so users download fresh assets on software updates.
<link href="{{ asset_rev('resources/assets/operator/css/main.css') }}" rel="stylesheet" type="text/css" />
Checks if the user is logged in, works for both frontend and operator panel.
{% if auth_check() %}
Fetches the authenticated user (or operator). Returns null
if the user is not logged in.
{{ auth_user().formatted_name }}
Returns a formatted date for a timestamp based on the settings in the help desk.
{{ formatDate(item.created_at) }}
Returns a relative date for a timestamp, such as '2 days ago'.
{{ timeago(ticket.created_at) }}
By default, we only allow certain PHP functions to be used in the templates. You can add additional functions to the configuration if you'd like to use them in the Twig code, below is an example of adding the count() and substr() functions.
twigbridge.php
in the /config/production
folder instead of updating the twigbridge.php
found in the main /config
folder, this will mean your configuration is not lost when you update your system.<?php
return [
'extensions' => [
'functions' => [
'count',
'substr'
],
],
];
Article Number: 251
Author: Jul 22, 2024
Last Updated: Jul 22, 2024
Online URL: https://docs.supportpro.vn/article/templates-251.html