Important
You are browsing the documentation for version 3.1 of OroCommerce, OroCRM and OroPlatform, which is no longer maintained. Read version 5.1 (the latest LTS version) of the Oro documentation to get up-to-date information.
See our Release Process documentation for more information on the currently supported and upcoming releases.
TWIG Filters¶
HTML¶
oro_html_sanitize¶
The oro_html_sanitize filter removes HTML elements except those that are allowed. You can find the list of allowed HTML tags in the app.yml file.
1{{ data|oro_html_sanitize() }}
Example
{% set data %}
<h1>Header</h1>
<div class="container" data-label="Container Label" id="root">
<p>Paragraph 1: <strong>Strong</strong> like <b>Bold</b></p>
<p>Paragraph 2: <em>Italic</em></p>
<script type="text/javascript">alert("Hello World!");</script>
</div>
{% endset %}
{{ data|oro_html_sanitize() }}
will print result:
1 <div class="test">
2 <h1>Header</h1>
3 <p>Paragraph 1: <strong>Strong</strong> like <b>Bold</b></p>
4 <p>Paragraph 2: <em>Italic</em></p>
5 </div>
oro_html_escape¶
The oro_html_escape filter allows HTML tags, all forbidden tags are escaped.
1{{ data|oro_html_escape() }}
Example
1 {% set data %}
2 <p>Paragraph 1: <strong>Strong</strong> like <b>Bold</b></p>
3 <p>Paragraph 2: <em>Italic</em></p>
4 <script type="text/javascript">alert("message");</script>
5 {% endset %}
6
7 {{ data|oro_html_escape() }}
will print result:
1 <p>Paragraph 1: <strong>Strong</strong> like <b>Bold</b></p>
2 <p>Paragraph 2: <em>Italic</em></p>
3 <script type="text/javascript">alert("message");</script>
Array¶
Sort By¶
The oro_sort_by filter sorts an array by a property. The following example shows how items can be sorted by priority:
1 {% set dataBlocks = [
2 {
3 'title': 'orocrm.account.sections.general'|trans,
4 'class': 'active',
5 'subblocks': generalSectionBlocks
6 },
7 {
8 'title': 'orocrm.account.sections.sales'|trans,
9 'priority': 100,
10 'subblocks': salesSectionBlocks
11 }
12 ] %}
13 {% if channelSectionBlocks %}
14 {% set dataBlocks = dataBlocks|merge([
15 {
16 'title': 'orocrm.account.sections.channels'|trans,
17 'priority': 50,
18 'subblocks': channelSectionBlocks
19 }
20 ]) %}
21 {% endif %}
22
23 {% set data = {'dataBlocks': dataBlocks} %}
24
25 {% set dataBlocks = data.dataBlocks|oro_sort_by %}
In this example, channelSectionBlocks can be empty and in this case it should not be rendered. However, if channels exist, then this block should be rendered between the general and sales blocks. To achieve this, set the priority property for channels and sales blocks and then use the oro_sort_by filter to sort blocks in the correct order.
You can also use the following options to tune oro_sort_by filter:
property - The path of the property by which the array should be sorted. It can be just the property name or any valid expression supported by Symfony PropertyAccess Component. The default value of this option is priority.
reverse - Indicates whether the sorting should be performed in reverse order. The default value of this option is false.
sorting-type - The sorting type. You can use number, string or string-case. The string-case means that case-insensitive string comparison should be used. The default value of this option is number.
The following example shows how you can sort array by name property using case-insensitive comparison:
1{% set items = items|oro_sort_by({'property': 'name', 'sorting-type': 'string-case'}) %}