/
smarty.html
43 lines (36 loc) · 1.56 KB
/
smarty.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
---
layout: default
navPage: docs
heading: smarty/
breadcrumbs:
- Module Development,/module_development/
- Form Tools 2,/module_development/index_ft2/
- Anatomy of a Module,/module_development/anatomy/
- smarty/
prev: library.php,/module_development/file_library/
next: Special Functions,/module_development/special_functions/
categories: module_development
---
{% include open_section.html nav='nav_module_development.html' selected='folder_smarty' nav_width=4 %}
<p>
One of the many nice things about using Smarty templates is that you can abstract away
logic and content into separate libraries, saving you having to write duplicate code and
helping you keep the template file as clean and uncluttered as possible. It helps your
templates stay focused as possible on what it <b>should</b> be handling: the appearance
and presentation of the data - and not the logic.
</p>
<p>
For example, say you need to display a "Province/State" dropdown on multiple pages in
your module. First, you can write separate PHP function to generate the HTML content,
then second, you can write a separate Smarty function file to use that PHP that can be
called directly in your templates like so:
</p>
{% codemirror smarty %}
{state_dropdown default=$default_state}
{% endcodemirror %}
<p>
All your Smarty functions and modifiers belong in the /smarty subfolder of your module
folder. By defining them there, they are automatically accessible to your template
pages within your module pages and even within the core script.
</p>
{% include close_section.html %}