No quote available.

Special Smarty Templating/Plugin Features


Inside any Smarty .tpl file you can manually execute certain plugins. You can use these Smarty functions:

  • {serendipity_printSidebar side="left|right|hidden|*" template="yourtemplate.tpl"}
    Returns a sidebar. The "side" parameter specifies which sidebar plugins to fetch. "*" means all plugins. The optional "template" parameter specifies the name of the template file used to emit each sidebar. Sidebar.tpl will be used to emit sidebars if custom template file is not specified.
  • {serendipity_hookPlugin hook="hookname" hookAll="true|false" data=$eventData addData=$addData}
    This allows to execute any plugins to call via the Event Plugin API. Using this execution method you can also execute your own created event hooks. The "hook" parameter specifies the used hook name, if "hookAll" is set to true, any plugin hook can executed. If it is not set or set to false, only the hooks "frontend_header", "entries_header", "entries_footer" and "frontend_comment" can be executed via Smarty. Via the "data" and "addData" variables you can pass custom variables to the PHP Plugin API functions.
  • {serendipity_showPlugin class="serendipity_your_nugget" id="serendipity_your_plugin:21323223efsd22aa" side="left|right|hidden|*" negate="null|true"}
    This allows to emit any sidebar plugin at your choses location. Either specify the "class" or "id" parameter (NOT both!) to indicate which plugin(s) should be called. The "class" attributes specifies a Plugin classname like serendipity_plugin_flickr, and would return the output of all installed plugins. If you specify the "id" attribute, you need the actual plugin ID found in the serendipity_plugins DB table. Via the "side" parameter you can restrict the output to a certain sidebar.
    Note that if you use this method to show a plugin for the left or right sidebar, that output is already displayed in your sidebar. You can set a plugin to hidden inside the Plugin Configuration Administration, and then make the Smarty function emit this hidden plugin, because hidden plugins are not contained in the sidebar. The "negate" attributes will reverse the output to show all plugins not matching the side/id/class restrictions.
  • {serendipity_getFile file="xxx"}
    Returns the absolute HTTP path to a file inside your template directory. Those calls are used to fetch files like Icons or Plugins which may be template-dependant
  • {serendipity_printComments entry="123" mode="..."}
    Fetches all comments (using comments.tpl) to a certain entry id. The mode specifies threaded or chronological mode.
  • {serendipity_printTrackbacks entry="123"}
    Fetches all trackbacks to a certain entry id.
  • {serendipity_fetchPrintEntries}
    (Serendipity 1.0-alpha and up)
    Prints a list of entries with a lot of special parameters:
The category ID (seperate multiple with ";") to fetch entries from

The author ID (seperate multiple with ";") to fetch entries from

The number of the page for paginating entries

The ID of an entry. If given, only a single entry will be fetched. 
If left empty, multiple entries are fetched.

Restricts fetching entries to a specific timespan. Behaves 
differently depending on the type:

  YYYYMMDD - Shows all entries from YYYY-MM-DD. 
  If DD is "00", it will show all entries from that month. 
  If DD is any other number, it will show entries 
  of that specific day.

 2-Dimensional Array:
  Key #0   - Specifies the start timestamp (unix seconds)
  Key #1   - Specifies the end timestamp (unix seconds)

 Other (null, 3-dimensional Array, ...):
  Entries newer than $modified_since will be fetched 

Indicates if the full entry will be fetched (body+extended: TRUE), 
or only the body (FALSE).

Holds a "Y" or "X, Y" string that tells which entries to fetch. 
X is the first entry offset, Y is number of entries. If not set, 
the global fetchLimit will be applied (15 entries by default)

Indicates whether drafts should be fetched (TRUE) or not

Holds a unix timestamp to be used in conjunction with $range, 
to fetch all entries newer than this timestamp

Holds the SQL "ORDER BY" statement.

Can contain any SQL code to inject into the central SQL statement 
for fetching the entry

If set to TRUE, all entries will be fetched from scratch and any 
caching is ignored

If set to TRUE, all sticky entries will NOT be fetched.

Can contain a SQL statement on which keys to select. 
Plugins can also set this, pay attention!

Can contain a SQL statement on how to group the query. 
Plugins can also set this, pay attention!

If set to "array", the array of entries will be returned. 
"flat-array" will only return the articles without their entryproperties. 
"single" will only return a 1-dimensional array. 
"query" will only return the used SQL.

Should an SQL-join be made to the AUTHORS DB table?

Should an SQL-join be made to the CATEGORIES DB table?

SQL-Parts to add to the "JOIN" query

Condition list of commaseparated entryproperties that 
an entry must have to be displayed.
Eexample: "ep_CustomField='customVal',ep_CustomField2='customVal2'")
(Available only in s9y >= 1.3)
Name of the template file to print entries with

Indicates if this is a preview

The name of the SMARTY block that this gets parsed into

Indicates whether to apply footer/header event hooks

Indicates whether the pagination footer should be displayed

Indicates whether the input $entries array is already grouped 
in preparation for the smarty $entries output array [TRUE], or 
if it shall be grouped by date [FALSE]

If TRUE, no plugins will be executed at all

Can be set to an array of plugin hooks to NOT execute

If set to TRUE, the smarty $entries array will NOT be 
cleared (to prevent possible duplicate output of entries)


The following modifiers are currently available:

  • {$variable|makeFilename}
    This transforms a variable into a valid HTTP URL name
  • {$variable|xhtml_target}
    This will either return a HTML compliant target attribute (with $variable as target name) or return a XHTML compliant Java Script? command. The actual returned value is determined by your Blog's configuration directive whether XHTML compliance is activated.
  • {$variable|formatTime:"%d.%m.%Y":true}
    This returns a properly formatted timestamp depending on the blog's language. The first parameter are valid sprintf() values, the third parameter specifies whether a probably configured server time zone offset difference is applied (true) or not (false).

Insert your own PHP-Code

Each template can have a special file "" inside its directory. This file is usually not existing within the default template. But you can add it to your template directory to perform special PHP operations. In Serendipity 0.7 you could place that code directly into layout.php, but since that file got removed, you now need to enter PHP code at a seperate place.

The file is executed from Serendipity immediately after the Smarty framework has been created. That means, at this point you can enter any PHP code you like to modify things of the Smarty framework.

You could, for instance, create your own Smarty modifier with this code:

$serendipity['smarty']->register_function('my_custom_function', 'my_custom_function');

function my_custom_function($params, &$smarty) {
  return 'I customized this: ' . $params['stuff'];

By using that, you could access that registered function within all .tpl files. See the Smarty Documentation for the API of Smarty.

The file can also be used for any other PHP code you may want to execute before displaying any output.

If you want to include any foreign PHP scripts in the Serendipity pages, you can do that using the Smarty {include_php} function within any of your templates *.tpl files. The include_php function is not available in Smarty's "Secure Mode", so you have to disable that by adding this to your templates

$serendipity['smarty']->security = false;

(Leave out the <?php ?> tags if your file already has those)

Once you disabled the secure mode, you can use

{include_php file="/path/to/your/custom.php"}

for example in the index.tpl file at any place you need the output.

If you want to include foreign PHP scripts to show them on your own page, consider using the "External PHP" or "Wrap URL" event plugins available via Spartacus - or of course, creating your own simple PHP Serendipity Plugin. Head over to the Plugin API Docs for more information about this.

Smarty/PHP Markup within entries

The "Markup: Smarty" plugin allows you to insert Smarty markup into your entries, complete with the power Smarty offers you. PHP within entries is not allowed, as it imposes a huge security risk.

Of course you can use the method of a file as described above to register your custom PHP code, which you can then re-use inside your entry code!

So you can declare a my_magic_function() which executes the PHP code you want, and if you register the function inside the file you can re-use it in your entry.

"Custom Fields"

Serendipity 0.9 allows you to define custom fields within your entry, which you can display within an entry.

That means, you can create two custom fields called Listening and Playing (don't use whitespace or special characters for fieldnames). Create an entry, and fill in values for those two fields. Now edit your entries.tpl template and place the Smarty Codes

Now listening to: {$}

Now playing: {$}

anywhere you like inside the entry loop. Remember to prefix your property keyname with ep_. Then you'll see those fields at the place you configured. You can also add the usual Smarty markup to check if a variable is empty, and add some DIV or other tags to surround your output.

Now if you don't want to show actually typed customFields of an entry, but instead make your own plugin insert stuff at that place, you can do that either by the custom function calls mentioned above, or by making your plugin alter the $entry['properties'] array to inject new content.

Your plugin can just hook into one of the events where entries are fetched ('entry_display' or 'frontend_display' or even 'frontend_entryproperties') and then just set your $eventData property index to what you want to be displayed later on. As your template already contains the display code from above, it will just pick up the new $entry['properties'] data from your custom plugin and show it, just as if you entered it on the entry creation screen.

Showing entries in foreign webpages

You can quite easily "show" Serendipity entries from other parts of your website, if PHP is available there and you have filesystem access to the Serendipity installation.

You can use the following PHP code to include the Serendipity framework and use the Serendipty API to display entries:

// 1: Switch to the Serendipity path. We need to use chdir so that the s9y framework can use its relative calls.

// 2: Start the Serendipity API
include '';

// 3: Start Smarty templating

// 4: Get the latest entries
$entries = serendipity_fetchEntries(null, true,1);

// 5: Put all the variables into Smarty

// 6: Get the template file
$tpl = serendipity_getTemplateFile('entries.tpl', 'serendipityPath');

// 7: Format and output the entries

// 8: Go back to where you came from

You can adapt each of the serendipity_fetchEntries() / serendipity_printEntries() calls to suit your needs. You can of course also pass any other template file instead of entries.tpl to the serendipity_getTemplateFile() call, so that you can have a custom layout for your entries in the PHP application, and use the default entries.tpl template in the real Serendipity installation.

To look up possible commands, check out the include/ file of your Serendipity installation to see phpDoc comments above the functions for which parameters you can use.