Page 1 of 1

custom ep_entryproperty field example

Posted: Wed Aug 07, 2013 2:34 pm
by Timbalu
This is an example of custom ep_entryproperty fields for the usage
with Serendipity >= 1.7 / Smarty 3

Install the event entryproperties Plugin.

In your templates config.inc.php add:

Code: Select all

// Simple example Gallery with Serendipity 1.7 for single entries 
// via entryproperties plugin, backends entry form area entryproperties, 
// and templates entries.tpl and config.inc.php
function serendipity_template_smarty_getdir($params, $smarty)  {
    global $serendipity;
    if (!empty($params['element']) && $dir = opendir($serendipity['serendipityPath'].$params['element'])) {
        while (false !== ($file = readdir($dir))) {
            if($file != ".." && $file != "." && strpos($file,'serendipityThumb.') == false) {
                $filelist[] = $file;
            }
        }
        closedir($dir);
        asort($filelist);
    }
    $smarty->assign('filelist', $filelist);
}
                      
$serendipity['smarty']->registerPlugin('function', 'serendipity_template_getdir', 'serendipity_template_smarty_getdir'); 
(*)

Create a new entry properties field eg. "EntriesGalleryPath" in entryproperties plugins config.

In backends entry form add to entry property field "EntriesGalleryPath" the value eg. "uploads/laos" (no quotes).

Now in your templates entries.tpl - inside the $entry loop - add:

Code: Select all

{serendipity_template_getdir element=$entry.properties.ep_EntriesGalleryPath}
and the output as a below body {$entry.body} example:

Code: Select all

        {$entry.body}
        {foreach $filelist as $file}
            <img src="{$serendipityHTTPPath}{$entry.properties.ep_EntriesGalleryPath}/{$file}" style="border: 1px solid #999; height: 16%; margin: 0.5em; padding: 0.2em; width: 16%;">
        {/foreach}
Better put the inline styles into your tempates (user) stylesheet css file and use eg. class="entryGallery".

Have fun! :)

(*)
If you only want the directory thumbs, which is recommended by using less resources, you could do this inside the function in a more modern way instead:

Code: Select all

    if (!empty($params['element'])) {
        foreach (glob($serendipity['serendipityPath'].$params['element'] . '/*.serendipityThumb.*') as $file) {
            $filelist[] = basename($file);
        }
        asort($filelist);
    }
    $smarty->assign('filelist', $filelist);
[/size]