[Catalyst] sending a variable to more than one tt2 template

Ian Sillitoe catalyst at sillit.com
Fri Mar 7 11:36:17 GMT 2008


yup, I'm using reusable TT2 widgets via [% PROCESS widget.tt2 %] to render
given objects (e.g. row of a given table) so I can call them from several
other TT2 pages (and on their own in AJAX calls).

root/src/foo/list.tt2
[% FOREACH foo =3D list_of_foos %]
  [% PROCESS foo/brief_summary.tt2
            entry =3D foo
  %]
[% END %]

root/src/foo/brief_summary.tt2
<h1>[% entry.title %]</h1>
<p>[% entry.content %]</p>

If you want to display the same widgets on the page for "bar" (which also
have "foos")

root/src/bar/list.tt2
[% FOREACH foo =3D bar.get_foos %]
  [% PROCESS foo/brief_summary.tt2
            entry =3D foo
  %]
[% END %]

FWIW I can then serve these widgets on their own in simple AJAX calls by
changing the wrapper applied in root/lib/site/wrapper (e.g. based on CGI
param "?format=3DAJAX"). Sending HTML snippets via AJAX is less efficient t=
han
sending JSON and client-side rendering with javascript (Jemplate), but when
the components are small and simple, I've found this useful.

Ian

On Fri, Mar 7, 2008 at 12:43 AM, Byron Young <Byron.Young at riverbed.com>
wrote:

>  You can call another template from within the template you specified in
> the stash, and pass the stash parameters along.  I don't use TT, but I th=
ink
> PROCESS is how you call other templates.
>
> HTH
>
> Byron
>
>  ------------------------------
> *From:* Emily Heureux [mailto:emily at burnham.org]
> *Sent:* Thursday, March 06, 2008 2:36 PM
> *To:* 'The elegant MVC web framework'
> *Subject:* [Catalyst] sending a variable to more than one tt2 template
>
>  Hi, I have a variable in a Controller method sent to the stash for a
> particular tt file.  What if I want that same variable to be available to
> another tt file?  I assume I cannot set two templates in one method.
>
>
>
> Thanks,
>
> Emily
>
>
>
> _______________________________________________
> List: Catalyst at lists.scsys.co.uk
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive:
> http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
> Dev site: http://dev.catalyst.perl.org/
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20080307/865a4=
1cf/attachment.htm


More information about the Catalyst mailing list