The reason this doesn't work in HTML::Template is because TMPL_INCLUDEs are handled in the first parsing phase, and TMPL_VAR's and every other TMPL_ tag are handled in the second parsing phase.
The first phase parses the template and checks to make sure all tags are balanced and consistent, and also reads in and merges any TMPL_INCLUDEs leaving one big template. The results are then optionally cached in case they are needed for a second run.
By the time the second phase runs, which does the actual variable substitutions, there is no record of what was an include, everything looks like one big template.
There is an alternate (very simple) way that you could handle it, using simple TMPL_IF conditionals:
Stuff here <TMPL_IF NAME="NEED_INCLUDE_1"> <TMPL_INCLUDE NAME="INCLUDE_1"> </TMPL_IF> <TMPL_IF NAME="NEED_INCLUDE_2"> <TMPL_INCLUDE NAME="INCLUDE_2"> </TMPL_IF> - or with HTML::Template::Expr - <TMPL_IF EXPR="DYNAMIC_INCLUDE eq 'include_file_1.tmpl'"> <TMPL_INCLUDE NAME="include_file_1.tmpl"> </TMPL_IF> Stuff here
But keep in mind that every one of the includes will be read in and parsed in the first phase, so it can be expensive if you have a lot of dynamic includes. Using the caching system will alleviate that somewhat. It is also made somewhat more awkward since HTML::Template doesn't have an ELSIF tag.
Your best bet is probably to go with the 2 Template object method explained by another poster...
- Cees
In reply to Re: HTML::Template .... misfeature?
by cees
in thread HTML::Template .... misfeature?
by dragonchild
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |