Back
Forms
Templates
Templates
Forward


Step 5: Using Templates

Horde_Template is the bTemplate engine ported to Horde. Extended to support gettext strings. Very fast (one pass, no regular expressions, only fast str_*() PHP methods.


<?php

/* Load libraries. */
require_once MOPPLE_BASE . '/lib/base.php';
require_once
MOPPLE_BASE . '/lib/Driver.php';
require_once
'Horde/Template.php';

/* Initialize driver. */
$driver = &Mopple_Driver::singleton($conf['storage']['driver']);
$driver->retrieve();

/* Retrieve MP3s. */
$mp3s = $driver->listMP3s();
if (
is_a($mp3s, 'PEAR_Error')) {
    
$notification->push($mp3s, 'horde.error');
    
$mp3s = array();
}

/* Create links and icons. */
foreach ($mp3s as $id => $mp3) {
    
$show_url = Horde::applicationUrl('mp3.php');
    
$show_url = Util::addParameter($show_url, array('id' => $mp3['song_id']));
    
$mp3s[$id]['link'] = Horde::link($show_url, sprintf(_("Show Song \"%s\""),
                                                        
$mp3['song_title']));
    
$edit_icon = Horde::img('edit.png',
                            
sprintf(_("Edit Song \"%s\""), $mp3['song_title']),
                            
'',
                            
$registry->getImageDir('horde'));
    
$edit_url = Horde::applicationUrl('edit.php');
    
$edit_url = Util::addParameter($edit_url, array('id' => $mp3['song_id']));
    
$mp3s[$id]['edit'] = Horde::link($edit_url, sprintf(_("Edit Song \"%s\""),
                                                        
$mp3['song_title'])) .
        
$edit_icon . '</a>';
}

/* Setup template. */
$template = &new Horde_Template();
$template->setOption('gettext', true);
$template->set('mp3s', $mp3s);
$template->set('edit_icon', Horde::img('edit.png', _("Edit Song"), '', $registry->getImageDir('horde')));

$title = _("List");

/* Output HTML. */
require MOPPLE_TEMPLATES . '/common-header.inc';
require
MOPPLE_TEMPLATES . '/menu.inc';
echo
$template->fetch(MOPPLE_TEMPLATES . '/list.html');
require
$registry->get('templates', 'horde') . '/common-footer.inc';

?>