]> sipb.mit.edu Git - ikiwiki.git/commitdiff
add readtemplate hook
authorSimon McVittie <smcv@debian.org>
Fri, 21 Feb 2014 21:10:43 +0000 (21:10 +0000)
committerSimon McVittie <smcv@debian.org>
Wed, 5 Mar 2014 10:42:19 +0000 (10:42 +0000)
IkiWiki.pm
doc/plugins/write.mdwn

index e5da04a3bb86d8aa47d96cac3df679623ad707ee..5e17c4a738a62422ed5a7a1ab613105bb6b02bb9 100644 (file)
@@ -2021,11 +2021,19 @@ sub template_depends ($$;@) {
        if (defined $page && defined $tpage) {
                add_depends($page, $tpage);
        }
        if (defined $page && defined $tpage) {
                add_depends($page, $tpage);
        }
-       
+
        my @opts=(
                filter => sub {
                        my $text_ref = shift;
                        ${$text_ref} = decode_utf8(${$text_ref});
        my @opts=(
                filter => sub {
                        my $text_ref = shift;
                        ${$text_ref} = decode_utf8(${$text_ref});
+                       run_hooks(readtemplate => sub {
+                               ${$text_ref} = shift->(
+                                       id => $name,
+                                       page => $tpage,
+                                       content => ${$text_ref},
+                                       untrusted => $untrusted,
+                               );
+                       });
                },
                loop_context_vars => 1,
                die_on_bad_params => 0,
                },
                loop_context_vars => 1,
                die_on_bad_params => 0,
index d2d1a6329c4c9c0cf0429d14f35b820ce5329e06..f4620b62328b4c0f7f611bc2ba21d21914855565 100644 (file)
@@ -211,6 +211,26 @@ them to `%links`. Present in IkiWiki 2.40 and later.
 The function is passed named parameters "page" and "content". Its return
 value is ignored.
 
 The function is passed named parameters "page" and "content". Its return
 value is ignored.
 
+### <a name="readtemplate">readtemplate</a>
+
+       hook(type => "readtemplate", id => "foo", call => \&readtemplate);
+
+Runs on the raw source of a page or `*.tmpl` file that is being
+used as a template, before it is parsed by [[!cpan HTML::Template]].
+
+The function is passed named parameters:
+
+* `id`: the name under which the template was looked up,
+  such as `page.tmpl` or `note`
+* `page`: the name of the template as a page or attachment in the wiki,
+  such as `templates/note`, or `undef` if it's outside the wiki (e.g. in
+  `/usr/share/ikiwiki/templates`)
+* `content`: the content of the corresponding file
+* `untrusted`: true if the template was loaded from the wiki or an underlay,
+  false if it was loaded from a trusted location
+
+It should return the replacement content.
+
 ### <a name="filter">filter</a>
 
        hook(type => "filter", id => "foo", call => \&filter);
 ### <a name="filter">filter</a>
 
        hook(type => "filter", id => "foo", call => \&filter);