There are a few ways you could achieve this.
1. Nested TRY / CATCH blocks in template:
[%
TRY;
INCLUDE 'yes-no-radio.tt2';
CATCH;
TRY;
INCLUDE 'radio.tt2';
CATCH;
TRY;
INCLUDE 'input.tt2';
CATCH;
THROW error;
END;
END;
END;
%]
2. You could also define a BLOCK to automate the TRY / CATCH
behavior:
[%
BLOCK include_one;
IF files.size > 0;
SET file_found = 0;
FOREACH file = files;
TRY;
INCLUDE $file;
file_found = 1;
CATCH;
IF loop.last;
THROW error;
END;
END;
IF file_found;
LAST;
END;
END;
END;
END;
%]
[%
INCLUDE include_one files = [
'yes-no-radio.tt2',
'radio.tt2',
'input.tt2'
]
%]
3. Additionally, you could let Template Toolkit do the work for you
and use multiple include paths. This may not be very efficient
though if you have a large number of possible variations for any
given template.
You would just create your template object like so:
$template = new Template (
INCLUDE_PATH => ['/path/yes-no', '/path/radio', '/path/input']
);
Based on the above path assumptions, your directory structure
would be similar to the following:
/path
/yes-no
input.tt2
/radio
input.tt2
/input
input.tt2
In your template, you can specify a single file in your INCLUDE
statement. Template Toolkit will happily try each include path in
turn until it has found a match.
[% INCLUDE 'input.tt2' %]
Note: This method is only going to fail-over when it cannot find a
particular template in the chain. If one is found and throws an
error, the chain will be broken.
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Behalf Of Dennis Sutch
Sent: Thursday, November 11, 2004 8:06 AM
To: [EMAIL PROTECTED]
Subject: [Templates] include from list of filenames?
Is there some method (perhaps a plugin) that performs an include from
a list of filenames?
For example, if the primary template finds that it needs to include
another template using an array of filenames (such as
"yes-no-radio.tt2", "radio.tt2", and "input.tt2"), it first attempts
to include "yes-no-radio.tt2" and if that fails then it attempts to
load the next filename....
Thanks in advance.
- Dennis
--
"Thanks to the crew of rocketscientists.ca for the gmail invitation!"
http://www.rocketscientists.ca/
_______________________________________________
templates mailing list
[EMAIL PROTECTED]
http://lists.template-toolkit.org/mailman/listinfo/templates
_______________________________________________
templates mailing list
[EMAIL PROTECTED]
http://lists.template-toolkit.org/mailman/listinfo/templates