From: anarcat Date: Wed, 15 Jul 2020 16:05:17 +0000 (-0400) Subject: why do not we have the page path in the template variables? X-Git-Url: http://git.vanrenterghem.biz/git.ikiwiki.info.git/commitdiff_plain/50a8f03bb7c18be56e760538a263b52c85aea94d why do not we have the page path in the template variables? --- diff --git a/doc/todo/include_page_variable_in_base_templates.mdwn b/doc/todo/include_page_variable_in_base_templates.mdwn new file mode 100644 index 000000000..9e4a6dc36 --- /dev/null +++ b/doc/todo/include_page_variable_in_base_templates.mdwn @@ -0,0 +1,38 @@ +[[!template id=gitbranch 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: + + + + + +... 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... + +[[!tag patch]]