Template Toolkit BLOCK in INCLUDE file
Hi all: I was looking at defining some TT BLOCKs in an include file which I would INCLUDE into my main template and then PROCESS as needed (as part of bug 13631 http://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=13631). However, I noticed that you can't access a BLOCK in an included file. I noticed some seemingly non-functional examples already in the Koha codebase. For instance, in "koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-auth-detail.tt" we try to process the blocks from the include "/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-authorities.inc", but from what I can see. none of them work (you can try for yourself at "/cgi-bin/koha/opac-authoritiesdetail.pl") . I also did heaps of tests myself. If you PROCESS or INCLUDE another file, you get everything EXCEPT the BLOCK. It does seem like there are some ways around this though. 1) If you use the EXPOSE_BLOCKS option in the Template->new() constructor, you can directly INCLUDE/PROCESS a BLOCK from an included file. (http://mail.template-toolkit.org/pipermail/templates/2002-July/003460.html) . However, this option isn't documented in the official website at all, so I'd be hesitant to use this. 2) When you INCLUDE/PROCESS an external file, you can pass variables to it. You could pass a variable to the external file, and have it execute PROCESS/INCLUDE from within that file. At the moment, I'm doing the second. David Cook Systems Librarian Prosentient Systems 72/330 Wattle St, Ultimo, NSW 2007
Hello David, Could you please give (even) more detail? I think I don't understand what you are saying, I tested with a simple example and it seems to work: diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-authorities.inc b/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-authorities.inc index aed68e5..d94ab92 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-authorities.inc +++ b/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-authorities.inc @@ -1,3 +1,7 @@ +[% BLOCK test %] +==== This is a test! [% s %]==== +[% END %] + [% BLOCK showhierarchy %] [% FOREACH tree IN trees %] [% PROCESS showtree tree = tree %] diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-auth-detail.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-auth-detail.tt index 703cea3..41c61e2 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-auth-detail.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-auth-detail.tt @@ -58,6 +58,7 @@ [% PROCESS otherscript headings=summary.otherscript wantcategory='preferred' %] </div> +[% PROCESS test s="Does it work?"%] [% IF summary.seefrom.size %] <div class="authstanza seefrom"> <div class="authstanzaheading">Used for/see from:</div> I see ==== This is a test! Does it work?==== 2015-01-28 4:30 GMT+01:00 David Cook <dcook@prosentient.com.au>:
Hi all:
I was looking at defining some TT BLOCKs in an include file which I would INCLUDE into my main template and then PROCESS as needed (as part of bug 13631 http://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=13631).
However, I noticed that you can’t access a BLOCK in an included file. I noticed some seemingly non-functional examples already in the Koha codebase. For instance, in “koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-auth-detail.tt” we try to process the blocks from the include “/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-authorities.inc”, but from what I can see… none of them work (you can try for yourself at “/cgi-bin/koha/opac-authoritiesdetail.pl”) . I also did heaps of tests myself. If you PROCESS or INCLUDE another file, you get everything EXCEPT the BLOCK.
It does seem like there are some ways around this though…
1) If you use the EXPOSE_BLOCKS option in the Template->new() constructor, you can directly INCLUDE/PROCESS a BLOCK from an included file. (http://mail.template-toolkit.org/pipermail/templates/2002-July/003460.html).
However, this option isn’t documented in the official website at all, so I’d be hesitant to use this.
2) When you INCLUDE/PROCESS an external file, you can pass variables to it. You could pass a variable to the external file, and have it execute PROCESS/INCLUDE from within that file.
At the moment, I’m doing the second…
David Cook
Systems Librarian
Prosentient Systems
72/330 Wattle St, Ultimo, NSW 2007
_______________________________________________ Koha-devel mailing list Koha-devel@lists.koha-community.org http://lists.koha-community.org/cgi-bin/mailman/listinfo/koha-devel website : http://www.koha-community.org/ git : http://git.koha-community.org/ bugs : http://bugs.koha-community.org/
I recall using it and testing it somewhere (...) in Koha and having it work fine too.. Mabye it is just little less obvious and a combination of things?
Could you please give (even) more detail? I think I don't understand what you are saying, I tested with a simple example and it seems to work:
However, I noticed that you can’t access a BLOCK in an included file. I noticed some seemingly non-functional examples already in the Koha codebase.
Hi Jonathan and Marcel: Thanks for your messages! I've realized my mistake... 1) When I was testing "opac-auth.detail.tt" and "opac-authorities.inc", my debugging strings weren't making it through, but I think that jstree was deleting them, which is why I didn't see them. I tried removing [% PROCESS 'opac-authorities.inc' %], and that quickly showed me that it was, in fact, working. 2) My mistake was that I was using [% INCLUDE 'external_file.inc' %], which doesn't work because it locally scopes all the variables. So the variable associated with the block will never be shared outside of the include file. However, if one uses the PROCESS directive, like in opac-auth.detail.tt, it works because it doesn't locally scope its variables, so they're accessible to the including file. It was just me not understanding the Template Toolkit instructions and the scoping of the blocks. Thanks again for having me look at this again : ). David Cook Systems Librarian Prosentient Systems 72/330 Wattle St, Ultimo, NSW 2007
-----Original Message----- From: koha-devel-bounces@lists.koha-community.org [mailto:koha-devel- bounces@lists.koha-community.org] On Behalf Of Marcel de Rooy Sent: Wednesday, 28 January 2015 11:03 PM To: koha-devel@lists.koha-community.org Subject: Re: [Koha-devel] Template Toolkit BLOCK in INCLUDE file
I recall using it and testing it somewhere (...) in Koha and having it work fine too.. Mabye it is just little less obvious and a combination of things?
Could you please give (even) more detail? I think I don't understand what you are saying, I tested with a simple example and it seems to work:
However, I noticed that you can't access a BLOCK in an included file. I noticed some seemingly non-functional examples already in the Koha codebase.
Koha-devel mailing list Koha-devel@lists.koha-community.org http://lists.koha-community.org/cgi-bin/mailman/listinfo/koha-devel website : http://www.koha-community.org/ git : http://git.koha- community.org/ bugs : http://bugs.koha-community.org/
participants (3)
-
David Cook -
Jonathan Druart -
Marcel de Rooy