On Fri, Jan 07, 2005 at 11:23:23AM -0500, Perrin Harkins wrote:
> On Fri, 2005-01-07 at 08:11 -0800, Bill Moseley wrote:
> I'm not sure I'm following, but the difference between INCLUDE and
> PROCESS is that INCLUDE prevents the specific side-effect of changing
> data in the stash and is therefore slower.  If you don't need to prevent
> that side-effect, then INCLUDE is the wrong thing to use.

That's the point, I guess.  How do I know if I need to prevent
side-effects or not?  Seems like something the caller should not be
concerned with, but rather the called template.

For example, if I want to show a list of files by calling
"show_file.tt" how do I know that "name" is going to get written
over?  Every time I want to INCLUDE or PROCESS some template I need to
go and look to see if it has side-effects and then use INCLUDE if it
does.

    [% name = "List of files in Directory" %]
    [%
        FOREACH file IN directory;
            PROCESS show_file.tt;
        END;
        "End of listing for: $name";
    %]

show_file.tt:

    [%
        # Localize some vars for easier use
        size = file.size
        name = file.name
        time = file.mtime
    %]

    <tr>
        <td><a href="[% name %]">[% name %]</a></td>
        <td>[% Date.format( time )%]</td>
        <td align="right">[% format_size(size) %]</td>
    </tr>

I suppose the smart thing is to do something like:

   my = {
     size = file.size
     name = file.name
     time = file.time
   }

and then use my.size and reserver "my" for only use within templates.

But, frankly, I can't think of a better way.  Maybe vars set in
templates would be local unless specified with EXPORT, and child
templates do see the vars set in its parent's template.



-- 
Bill Moseley
[EMAIL PROTECTED]


_______________________________________________
templates mailing list
[email protected]
http://lists.template-toolkit.org/mailman/listinfo/templates

Reply via email to