Sophie

Sophie

distrib > Mageia > 5 > x86_64 > media > core-release > by-pkgid > d9faca8851758f10126d599e59ad5368 > files > 15

php-pear-HTML_Template_Sigma-1.3.0-3.mga5.noarch.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>Sigma example 4: callbacks</title>
</head>

<body>
<h1>&Sigma;<sub>template</sub> example 4: callbacks</h1>

<h2>1. Using callbacks for minor presentation changes</h2>
<p>Here we use callback function to iterate between two background colors of table cells. The beauty of this example is that all the logic to select the needed color is contained in the script, while the colors themselves are inside the template.</p>
<p>Note also that the callback is called only once per <b>parse()</b> call, that's because all of the calls are identical.</p>
<table cellpadding="2" cellspacing="0" border="1">
    <tr>
        <th>Error code</th>
        <th>Error message</th>
        <th>Reason</th>
        <th>Solution</th>
    </tr>
<!-- BEGIN table_row -->
    <tr>
        <td bgcolor="func_bgcolor(#CCCCCC, #F0F0F0)">{code}</td>
        <td bgcolor="func_bgcolor('#CCCCCC', '#F0F0F0')">{message}</td>
        <td bgcolor="func_bgcolor('#CCCCCC',  '#F0F0F0')">{reason}</td>
        <td bgcolor="func_bgcolor('#CCCCCC', '#F0F0F0')">{solution}</td>
    </tr>
<!-- END table_row -->
</table>

<h2>2. Using callbacks for i18n</h2>
<p>You can plug in any kind of i18n solution as a callback for 'func_translate'. Note that all the messages are contained in the template and can be edited without touching scripts.</p>
<!-- BEGIN i18n_block -->
<h3>{language}</h3>
<ul>
    <li>func_translate(Username): {username}</li>
    <li><a href="#">func_translate(Find all posts by {username})</a></li>
    <li><a href="#">func_translate('Send private message')</a></li>
</ul>
<!-- END i18n_block -->

<h2>3. Shorthand for callbacks, built-in callbacks</h2>
<p>A common problem is to output the same variable, but encoded/processed in different ways. The shorthand &#x7b;var:callback&#x7d; for callback functions and default callbacks 'h', 'u' and 'j' were added specifically to address this.</p>
<script type="text/javascript">
function showMessage()
{
    alert("The message is: {escaped:j}");
}
</script>
<form>
<ul>
    <li>For output in HTML: {escaped:h}</li>
    <li>For output in URLs: <a href="?escaped={escaped:u}">a link</a></li>
    <li>For javascript: <input type="button" value="click me" onclick="showMessage();"></li>
    <li>Use a custom callback: {escaped:letters}</li>
</ul>
</form>

</body>
</html>