]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/commitdiff
why do not we have the page path in the template variables?
authoranarcat <anarcat@web>
Wed, 15 Jul 2020 16:05:17 +0000 (12:05 -0400)
committeradmin <admin@branchable.com>
Wed, 15 Jul 2020 16:05:17 +0000 (12:05 -0400)
doc/todo/include_page_variable_in_base_templates.mdwn [new file with mode: 0644]

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 (file)
index 0000000..9e4a6dc
--- /dev/null
@@ -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:
+
+    <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...
+
+[[!tag patch]]