summaryrefslogtreecommitdiff
path: root/doc/todo/varioki_--_add_template_variables___40__with_closures_for_values__41___in_ikiwiki.setup.mdwn
blob: d292a1184892132e880365370900f8c71fc0243c (plain)

varioki - Add variables for use in ikiwiki templates

This plugin attempts to provide a means to add templates for use in ikiwiki templates, based on a hash variable set in the ikiwiki configuration file. The motivation for this plugin was to provide an easy way for end users to add information to be used in templates -- for example, my "Blosxom" blog entry template does fancy things with the date components of the entry, and there was no easy way to get that information into the template. Or if one wants to have a different page template for the top level index page than for the rest of the pages inthe wiki (for example, to only put special content, like, say, 'last.fm" play lists, only on the front page).

This plugin hooks itsef into the "pagetemplate" hook, and adds parameters to the appropriate templates based on the type. For example, the following inserted into "ikiwiki.setup" creates "TMPL_VAR MOTTO" and "TOPLVL" which can then be used in your templates.

varioki => {
  ’motto’    => ’"Manoj\’s musings"’,
  ’toplvl’   => ’sub {return $page eq "index"}’
},

For every key in the configured hash, the corresponding value is evaluated. Based on whether the value was a stringified scalar, code, array, or hash, the value of the template parameter is generated on the fly. The available variables are whatever is available to "pagetemplate" hook scripts, namely, $page, $destpage, and $template. Additionally, the global variables and functions as defined in the Ikiwiki documentation (http://ikiwiki.info/plugins/write/) may be used.

ManojSrivastava

I think you could now implement "toplvl" using [[conditionals|/plugins/conditional]]:

\[[!if test="destpage(/index)" then="""...""" else="""..."""]]

--[[JoshTriplett]]

Right. But how about some more complex stuff, for example, from my varioki settings below? --ManojSrivastava

Here's a dump of the file Manoj sent me, for reference.

My take on this is that simple plugins can do the same sort of things, this is kind of wanting to avoid the plugin mechanism and just use templates and stuff in the config file. Not too thrilled about that. --[[Joey]]

OK. How do you implement something like category I have in my varioki settings? As a user, I can just add new stuff to my config and my template; with a plugin I'll have to write a plugin, and install it in the ikiwiki plugin directory, which is not very easy for a plain ol' user. Not everyone is the sysadmin of their own machines with access to system dirs. --ManojSrivastava

It seems worth mentioning here that the libdir configuration parameter lets you install additional plugins in a user-controlled directory (libdir/IkiWiki/Plugin), avoiding needing root; indeed, a full local ikiwiki installation without any involvement from the sysadmin is [[possible|tips/DreamHost]]. --[[smcv]]

I'd argue in favour of this plugin; it's true that a simple plugin can be used to set a template variable, but that makes it necessary to write a new plugin for every variable (or set of variables) that are needed. In that kind of situation, I don't think bypassing the plugin mechanism is a bad thing, unless an ever-growing collection of plugins to set one or two variables is a good thing.

--[[bma]]


[[!tag patch]]