logo       

Re: including non-file templates: msg#00114

Subject: Re: including non-file templates
Thanks for the suggestions, but both of them error out with: file error - ablock: not found

Josh Rosenbaum <josh-2KZaVHFycl6akBO8gow8eQ@xxxxxxxxxxxxxxxx> wrote:
John Smith wrote:
> I want to be able to include a template component in a template where
> that component is not a file. I'm sure its somewhere in the man pages,
> but I can't find it. This is what I tried:
>
> perl code:
> use strict;
> use Template;
> my $block = <> ----------------------------------------------
> Hello, [% name %]
> ----------------------------------------------
> BLOCK
> my $tt = Template->new() or die;
> my $ttData =
> {
> blockdata => $block,
> name => 'John'
> };
> $tt->process("testblock.tt", $ttData) or die;
>
> testblock.tt:
> [% MACRO ablock BLOCK %]
> [% blockdata %]
> [% END %]
> [% I NCLUDE ablock %]
>
> Doesn't work. Any ideas?
> John Smith
>


Hi John,

I probably shouldn't post on this as I haven't tried what you mentioned. However, have you tried adding an "| eval" to the blockdata variable retrieve? My guess is that you are just getting the non-processed block you specified in the perl code above. (Let us know what you mean by "doesn't work" if it's not it.) :)

testblock.tt:
[% MACRO ablock BLOCK %]
[% blockdata | eval %]
[% END %]
[% INCLUDE ablock %]


As an alternative you might try the following, which I have also not tested, and am not sure will even work, but am just providing as something you can try. I've never tried two procesess, in a row, and am not sure whether they will have the same context or not, but if it worked, it'd be a simpler solution.

=================================================
perl code:
use strict;
use Template;
my $block = < [% BLOCK ablock %]
----------------------------------------------
Hello, [% name %]
----------------------------------------------
[% END %]
BLOCK
my $tt = Template->new() or die;
my $ttData =
{
blockdata => $block,
name => 'John'
};
my $result;
$tt->process(\$block, $ttData, \$result) or die;
$tt->process("testblock.tt", $ttData) or die;

testblock.tt:
[% INCLUDE ablock %]
=================================================


-- Josh

_______________________________________________
templates mailing list
templates-MnLy+PD7ppGDO3lXZvfOKmD2FQJk+8+b@xxxxxxxxxxxxxxxx
http://lists.template-toolkit.org/mailman/listinfo/templates

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
boot-loaders.gr...    php.pear.genera...    debugging.valgr...    kde.redhat.user...    text.xml.xsl.ge...    culture.languag...    hardware.microc...    java.servicemix...    redhat.release....    web.zope.plone....    user-groups.lin...    opendarwin.webk...    video.mjpeg.use...    sysutils.bcfg2....    encryption.gpg....    lx-office.devel...    xfree86.forum/2...    mail.mutt.devel...    acpi.devel/2003...    qnx.openqnx.dev...    network.irc.irs...    freebsd.devel.m...   
Home | blog view | USPTO Patent Archive | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe