Just wanted to start the ball rolling for the themesters by linking to Smarty. It looks like they've thought this through. I'll be spending lots of time with the manual over the holidays, between snoozes, visits, and holiday cheer.
Smarty rules!
I was testing it out and loved it right away. You can easily dynamically assign a class name to html/xhtml -elements.
eg.
in header.tpl
<link rel="stylesheet" href="{$style}" type="text/css">
</HEAD>
<BODY bgcolor="#ffffff">
<p {$style_class}>{$pInput}</p>
in php script:
require '../libs/Smarty.class.php';
$smarty = new Smarty;
$smarty->assign("style","/themes/liteblue/style.php");
$smarty->assign("style_class","class=\"teststyle\"");
$smarty->display('index.tpl');
I think this gives style designers wider range to create new themes or "skins".
- Janne -
Or perhaps more non-programmer way would be to make styles.conf file with every class name in it eg.
p_normal = normal
p_bold = pbold
load the styles.conf in template:
{config_load file=styles.conf}
and use them in like:
<p class="{#p_normal#}">{$content}</p>
<p class="{#p_bold#}">{$warning}</p>
and so on...
Is my understanding correct that the conversion to using smarty templates can be a gradual process? One can mix pages using smarty with old pages and one can even in one and the same script print some things straight to the page and display other things with smarty's $smarty->display(). If that is the case, what is stopping us from starting to use smarty templates immediately on all new code?
You are quite right, in the end everything should be done via Smarty templates and they should be fully XHTML compliant. The question was just how to get there. Apparently a continuous, step-by-step, conversion of Moodle to templates is possible. We don't have to rewrite all pages at once.
My experience of smarty so far.
I made one of my own projects with smarty and I did it with this "three layer model" (not exact science ).
Layer 1. - Datalayer (core). Contains the actual php code. Does not print anything.
Functions actually returns something that can be assigned to smarty class as a variable like
string, array or class.
Layer 2. - Smartylayer. Assigns variables to smarty class and outputs html/xhtml from templates.
Since it's combination of html/xhtml and smartycode, template/style designer can easily add all
the necessary style attributes to html/xhtml tags.
Layer 3. - Stylelayer (css) include stylesheets for current theme (whole theme if the theme is
build from several templates).
Example:
Function get_links returns an array of links from database (id, title, etc...).
Get the links.
$linkdata = get_links();
Assign it to smarty class and display template.
$smarty->assign("links",$linkdata);
$smarty->display("main.tpl");
And in main.tpl we actually loop through that $links array and print links to html table.
(this template also checks if the global variable "page" is set and
if/else statement to define what to do)
{section name=i loop=$links}
<table class="ntable" width="100%" cellpadding="2" cellspacing="0">
<tr>
<td class="ntd"><img src="{$theme}/button.gif" alt=""></td>
{if $smarty.get.page !="" and $smarty.get.page == $links[i].id and !$smarty.get.news}
<td class="ntd" align="right">{$links[i].title}<img src="{$theme}/spacer.gif" width="5" height="2" alt=""></td>
{elseif $smarty.get.page == "" and $links[i].isfp == 1 and !$smarty.get.news}
<td class="ntd" align="right">{$links[i].title}<img src="{$theme}/spacer.gif" width="5" height="2" alt=""></td>
{else}
<td class="ntd" align="right"><a class="vert" href="{$url}/?page={$links[i].id}">{$links[i].title}</a></td>
{/if}
</tr>
</table>
{/section}
I don't know if this is any help to anyone, but I hope it'll give some picture of using smarty template engine...
- Janne -
