function apply_template($data, $template)
{
    $piece = new xhtml_piece($template);
    foreach ($data as $key => $value) {
        $piece->set($key, $value);
    }
    return $piece->out();
}
 function LocalLibReferencePage(&$ref, $lib, $translation, $rel_path = '../../')
 {
     global $LANGUAGES;
     $lang = 'en';
     $this->filepath = "distribution/libraries/{$lib}/" . $ref->name();
     $title = $ref->title() . "\\ {$lib} \\ Language (API) \\ Processing 2+";
     $xhtml = new xhtml_page(TEMPLATEDIR . 'foundation-template.local.html');
     $xhtml->set('header', '<a href="http://processing.org/" title="Processing.org"><div class="processing-logo" alt="Processing cover"></div></a>');
     $xhtml->set('title', $title);
     $xhtml->set('bodyid', 'Library-ref');
     $xhtml->set('navigation', local_nav('Libraries', $rel_path));
     $piece = new xhtml_piece(TEMPLATEDIR . 'foundation-template.reference.item.html');
     $xhtml->set('content_for_layout', $piece->out());
     $xhtml->set('reference_nav', library_nav($lib));
     $xhtml->set('language_nav', language_nav($lang));
     foreach ($translation->attributes as $key => $value) {
         $xhtml->set($key, $value);
     }
     foreach ($translation->meta as $key => $value) {
         $xhtml->set($key, $value);
     }
     $xhtml->set('content', $ref->display());
     $xhtml->set('updated', date('F d, Y h:i:sa T', filemtime(CONTENTDIR . '/' . $ref->filepath)));
     $xhtml->set('relpath', $rel_path);
     $this->xhtml = $xhtml;
 }