About Features Downloads Getting Started Documentation Events Support GitHub

Love VuFind®? Consider becoming a financial supporter. Your support helps build a better VuFind®!

Site Tools


Warning: This page has not been updated in over over a year and may be outdated or deprecated.
legacy:vufind_1.x_developer_manual:building_a_smarty_plugin

This is an old revision of the document!


Building a Smarty Plugin

VuFind uses the Smarty Template Engine to control the HTML templates. Smarty has the ability to create plugins to be intergrated in with the templates. If you would like to create a Plugin to enhance VuFind - for example a SQL Query to your ILS Database for additional data on the Record View Page or a new query to the Solr data store - you could simply create a PHP file that lives within the /web/interface/plugins directory. Please follow the Smarty Documentation on how to create a plugin.

Here is an arbitrary example of a plugin that interacts with the Solr data store:

filename: /web/interface/plugins/function.showqauthors.php
<?php
/*
 * Smarty plugin
 * -------------------------------------------------------------
 * File:     function.showqauthors.php
 * Type:     function
 * Name:     Show Q Authors
 * Purpose:  Runs a SOLR query to find all Q authors
 * -------------------------------------------------------------
 */
function smarty_modifier_showqauthors()
{
    global $solr;
 
    $solr->raw = false; // Do not return Raw XML data (use array)
 
    $result = $solr->query('authorStr:Q*'); // Run Search
 
    // Create Output
    $html = "<ul>\n";
    foreach ($result['record'] as $record) {
        $html .= '<li>' . $record['author'] . "</li>\n";
    }
    $html .= "</ul>\n";
 
    // Return Output
    return $html;
}
?>
legacy/vufind_1.x_developer_manual/building_a_smarty_plugin.1449861321.txt.gz · Last modified: 2015/12/11 19:15 by demiankatz