Update:Archive/2.0/Developers Guide: Difference between revisions

Jump to navigation Jump to search
no edit summary
No edit summary
Line 56: Line 56:
=== Putting it together ===
=== Putting it together ===
An example document would look something like this:
An example document would look something like this:
<code>
<?php
/**
* FAQ page.
*
* @package amo
* @subpackage docs
*
* @todo FAQ search?
*/
$db->query("
    SELECT
        `title`,
        `text`
    FROM
        `faq`
    WHERE
        `active` = 'YES'
    ORDER BY
        `index` ASC,
        `title` ASC
",SQL_ALL, SQL_ASSOC);
$faq = $db->record;
$links = array(
    array(  'href'  => './faq.php',
            'title' => 'Frequently Asked Questions',
            'text'  => 'FAQ'),
    array(  'href'  => './policy.php',
            'title' => 'Addons Policies',
            'text'  => 'Policy')
);
// Send FAQ data to Smarty object.
$tpl->assign(
  array(  'faq'      => $faq,
            'links'    => $links,
            'sidebar'  => 'inc/nav.tpl',
            'content'  => 'faq.tpl',
            'title'    => 'Frequently Asked Questions')
);
// No need to set wrapper, since the left-nav wrapper is default.
// $wrapper = 'inc/wrappers/default.tpl';
?>
</code>


<?php
/**
  * FAQ page.
  *
  * @package amo
  * @subpackage docs
  *
  * @todo FAQ search?
  */
$db->query("
    SELECT
        `title`,
        `text`
    FROM
        `faq`
    WHERE
        `active` = 'YES'
    ORDER BY
        `index` ASC,
        `title` ASC
",SQL_ALL, SQL_ASSOC);
$faq = $db->record;
$links = array(
    array(  'href'  => './faq.php',
            'title' => 'Frequently Asked Questions',
            'text'  => 'FAQ'),
    array(  'href'  => './policy.php',
            'title' => 'Addons Policies',
            'text'  => 'Policy')
);
// Send FAQ data to Smarty object.
$tpl->assign(
    array(  'faq'      => $faq,
            'links'    => $links,
            'sidebar'  => 'inc/nav.tpl',
            'content'  => 'faq.tpl',
            'title'    => 'Frequently Asked Questions')
);
// No need to set wrapper, since the left-nav wrapper is default.
// $wrapper = 'inc/wrappers/default.tpl';
?>
Here we see standard usage of $db to query data, then the $tpl->assign() function assigns local variables to the Smarty template.  Here are some pointers:
Here we see standard usage of $db to query data, then the $tpl->assign() function assigns local variables to the Smarty template.  Here are some pointers:


Line 115: Line 114:
faq.tpl looks like this:
faq.tpl looks like this:


<code>
&lt;h1&gt;Frequently Asked Questions&lt;/h1&gt;
 
<h1>Frequently Asked Questions</h1>
 
<dl>
{section name=faq loop=$faq}
<dt>{$faq[faq].title}</dt>
<dd>{$faq[faq].text|nl2br}</dd>
{/section}
</dl>


&lt;dl&gt;
{section name=faq loop=$faq}
&lt;dt&gt;{$faq[faq].title}&lt;/dt&gt;
&lt;dd&gt;{$faq[faq].text|nl2br}&lt;/dd&gt;
{/section}
&lt;/dl&gt;


</code>


=== Input Filtering ===
=== Input Filtering ===
3,035

edits

Navigation menu