Customising/Themes/Differences between Smarty and Dwoo: Difference between revisions
From Mahara Wiki
< Customising | Themes
Brettwilkins (talk | contribs) (Created page with "Mahara 1.2 uses Dwoo instead of Smarty, as its templating engine. While there is considerable compatibility between the two engines, there are some things that will need to be …") |
mNo edit summary |
||
(One intermediate revision by one other user not shown) | |||
Line 5: | Line 5: | ||
<div id="section_1"> | <div id="section_1"> | ||
=== Cycle === | ===Cycle=== | ||
In Smarty, {cycle} arguments don't need to be quoted. In Dwoo, they must be. For example, {cycle values=r0,r1} works in Smarty, but must be changed to {cycle values='r0,r1} in Dwoo. | In Smarty, {cycle} arguments don't need to be quoted. In Dwoo, they must be. For example, {cycle values=r0,r1} works in Smarty, but must be changed to {cycle values='r0,r1} in Dwoo. | ||
Line 11: | Line 11: | ||
</div><div id="section_2"> | </div><div id="section_2"> | ||
=== Insert === | ===Insert=== | ||
Insert is used in Smarty to insert the return value of a function call, and skip caching. Eg {insert name="messages"} would call the php function insert_messages, and insert what it returned into the resulting template. | Insert is used in Smarty to insert the return value of a function call, and skip caching. Eg {insert name="messages"} would call the php function insert_messages, and insert what it returned into the resulting template. | ||
Line 19: | Line 19: | ||
</div><div id="section_3"> | </div><div id="section_3"> | ||
=== Use of "data" when including templates === | ===Use of "data" when including templates=== | ||
Both Smarty and Dwoo support including templates from within other templates, using {include}, and both support passing data between templates, using {include something='something'}. However, if you pass a variable called "data" in Dwoo, it will overwrite the existing data, because of naming collision. Therefore {include file='something.tpl' innerdata=$foo} must be used instead. | Both Smarty and Dwoo support including templates from within other templates, using {include}, and both support passing data between templates, using {include something='something'}. However, if you pass a variable called "data" in Dwoo, it will overwrite the existing data, because of naming collision. Therefore {include file='something.tpl' innerdata=$foo} must be used instead. | ||
Line 25: | Line 25: | ||
</div><div id="section_4"> | </div><div id="section_4"> | ||
=== Section === | ===Section=== | ||
In some places in Mahara 1.1, we were using {section} instead of Loops. This is really not properly compatible with Dwoo, it makes much more sense to just switch to a loop instead. | In some places in Mahara 1.1, we were using {section} instead of Loops. This is really not properly compatible with Dwoo, it makes much more sense to just switch to a loop instead. | ||
</div> | </div> | ||
[[Category:Customising]] |
Latest revision as of 18:08, 19 Haziran 2019
Mahara 1.2 uses Dwoo instead of Smarty, as its templating engine. While there is considerable compatibility between the two engines, there are some things that will need to be changed in existing templates.
Note that after 1.2, we will more and more move to Dwoo native syntax, rather than using the "Smarty compatible" syntax, but we'll keep backwards compatibility for 1.3 at least.
Cycle
In Smarty, {cycle} arguments don't need to be quoted. In Dwoo, they must be. For example, {cycle values=r0,r1} works in Smarty, but must be changed to {cycle values='r0,r1} in Dwoo.
Insert
Insert is used in Smarty to insert the return value of a function call, and skip caching. Eg {insert name="messages"} would call the php function insert_messages, and insert what it returned into the resulting template.
In Dwoo, this should be done using a native php call {insert_messages} and to bypass caching, be wrapped inside {dynamic} tags, like {dynamic}{insert_messages}{/dynamic}
Use of "data" when including templates
Both Smarty and Dwoo support including templates from within other templates, using {include}, and both support passing data between templates, using {include something='something'}. However, if you pass a variable called "data" in Dwoo, it will overwrite the existing data, because of naming collision. Therefore {include file='something.tpl' innerdata=$foo} must be used instead.
Section
In some places in Mahara 1.1, we were using {section} instead of Loops. This is really not properly compatible with Dwoo, it makes much more sense to just switch to a loop instead.