Available in a git repository branch.
Branch: anarcat/page-template-variable
Author: anarcat

I do not understand why, but it seems like base templates included in the theme do not have access to the current page path. All sorts of plugins give all sorts of information about the page including its title, modification time, related pages (trail and parentlinks), tags, fields and so on... But nothing on just that: the page path.

It's a one-line patch to fix:

modified   IkiWiki/Render.pm
@@ -123,6 +123,7 @@ sub genpage ($$) {
    }

    $template->param(
+       page => $page,
        title => $page eq 'index' 
            ? $config{wikiname} 
            : pagetitle(basename($page)),

The patch is available in my git repo, and also directly visible here:

https://gitlab.com/anarcat/ikiwiki/-/commit/9b471a6adcdf47e98dbe3a3aae68f3da4ab63fbb

I use this to include the page name in a tracking URL for (privacy-friendly) web analytics, thanks to Goatcounter. But it seems like a useful thing in general: for example, I remember a friend struggling to figure out how to theme the frontpage of his wiki differently, and he spent a long trying to figure out this very problem. I have myself spent about an hour scouring the source code before deciding the variable just did not exist.

The friend ended up using this construction instead:

<TMPL_UNLESS PARENTLINKS>
  <link rel="stylesheet" href="css/style-frontpage.css" />
</TMPL_UNLESS>

... which might actually be more elegant, but way less flexible: what if you want to theme another page that way? In other words, the above only works for the frontpage, but maybe you want /sales to be themed differently than /sandbox...

In general, I think this is a minor change that can have a huge impact on the themability of ikiwiki, if we care about that at all. ;)

Thanks!

PS: I think it would be great if we had a way to figure out which variables are available in a template... I couldn't find out how to do that in HTML::Template, and wonder if we could have some way to do that, to ease such diagnostics in the future...


you're not alone: I think this is very similar to how to put a permalink on each post.

PS: I think it would be great if we had a way to figure out which variables are available in a template

I agree! Perhaps a subroutine that enumerated them all and a plugin to expose it or something. I definitely wold find that useful too. ­— Jon, 2020-07-21