FAQ
Hi,
I'm new at the catalyst framework and using Template Toolkit.

What is the best practice to load a template like the following:


<html>
<body>
<div class"left">
[% content %]
</div>
<div class"right">
[% right_content %]
</div>
</body>
</html>

,content' should be replaced with left_content.tt2
,right_content' with right_content.tt2



If I use a Wrapper, only content is automatically replaced. How can I also
replace right_content?



Thanks for your Help!!

Stefan

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20110810/3d649d9b/attachment.htm

Search Discussions

  • Evan Carroll at Aug 10, 2011 at 7:11 pm
    The idea behind WRAPPER is that one of these includes is magical (CONTENT)

    TOP
    [% CONTENT %]
    BOTTOM

    That's not to say you can't more complex wrappers with INCLUDES or PROCESS

    TOP
    [% CONTENT %]
    [% INCLUDE foo.tt %]
    BOTTOM

    It just means that the content being WRAPPED is the destination
    template, and TT will use the WRAPPER as a post-processor of sorts.
    Now, if you want something like this:

    TOP
    [% CONTENT %]
    [% INCLUDE $foo %]
    BOTTOM

    Where `$foo` is set in whatever template CONTENT targets.. you can do
    that too, though I wouldn't know the exact syntax. It'd probably
    consist of setting

    DEFAULT foo = 'right_content.tt';

    In the CONTENT template.

    --
    Evan Carroll - me@evancarroll.com
    System Lord of the Internets
    web: http://www.evancarroll.com
    ph: 281.901.0011
  • Francisco Obispo at Aug 10, 2011 at 7:13 pm
    Look at the INCLUDE directive in perldoc Template::Manual::Directives

    INCLUDE
    The "INCLUDE" directive is used to process and include the output of another template file or block.

    [% INCLUDE header %]


    Francisco


    On Aug 10, 2011, at 12:00 PM, Stefan wrote:

    Hi,
    I?m new at the catalyst framework and using Template Toolkit.

    What is the best practice to load a template like the following:

    <html>
    <body>
    <div class?left?>
    [% content %]
    </div>
    <div class?right?>
    [% right_content %]
    </div>
    </body>
    </html>

    ?content? should be replaced with left_content.tt2
    ?right_content? with right_content.tt2

    If I use a Wrapper, only content is automatically replaced. How can I also replace right_content?

    Thanks for your Help!!
    Stefan
    _______________________________________________
    List: Catalyst@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/
    Francisco Obispo
    email: fobispo@isc.org
    Phone: +1 650 423 1374 || INOC-DBA *3557* NOC
    Key fingerprint = 532F 84EB 06B4 3806 D5FA 09C6 463E 614E B38D B1BE
  • Kieren Diment at Aug 10, 2011 at 9:15 pm

    On 11/08/2011, at 5:13 AM, Francisco Obispo wrote:

    Look at the INCLUDE directive in perldoc Template::Manual::Directives

    INCLUDE
    The "INCLUDE" directive is used to process and include the output of another template file or block.

    [% INCLUDE header %]
    You should usually PROCESS not INCLUDE as there's no copying of variables during processing, so it's faster: https://metacpan.org/module/Template::Manual::Directives#PROCESS

    On Aug 10, 2011, at 12:00 PM, Stefan wrote:

    Hi,
    I?m new at the catalyst framework and using Template Toolkit.

    What is the best practice to load a template like the following:

    <html>
    <body>
    <div class?left?>
    [% content %]
    </div>
    <div class?right?>
    [% right_content %]
    </div>
    </body>
    </html>

    ?content? should be replaced with left_content.tt2
    ?right_content? with right_content.tt2

    If I use a Wrapper, only content is automatically replaced. How can I also replace right_content?

    Thanks for your Help!!
    Stefan
    _______________________________________________
    List: Catalyst@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/
    Francisco Obispo
    email: fobispo@isc.org
    Phone: +1 650 423 1374 || INOC-DBA *3557* NOC
    Key fingerprint = 532F 84EB 06B4 3806 D5FA 09C6 463E 614E B38D B1BE






    _______________________________________________
    List: Catalyst@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/
  • Stefan Profanter at Aug 10, 2011 at 9:35 pm
    Thank you a lot guys for your help!!
    I've now find another solution by using the Wrapper directive
    (http://template-toolkit.org/docs/manual/Directives.html#section_WRAPPER )
    Where I can recursively parse the templates. I will now try to implement it
    with one of your solutions or with WRAPPER.

    Thanks!!
    Stefan
  • Aristotle Pagaltzis at Aug 11, 2011 at 11:51 am

    * Stefan [2011-08-10 21:05]:
    What is the best practice to load a template like the following:

    <html>
    <body>
    <div class"left">
    [% content %]
    </div>
    <div class"right">
    [% right_content %]
    </div>
    </body>
    </html>

    ,content' should be replaced with left_content.tt2
    ,right_content' with right_content.tt2


    If I use a Wrapper, only content is automatically replaced. How
    can I also replace right_content?
    If you want to make `right_content` dependent on the page, i.e.
    you want to define both a main content and some sidebar content
    *per page*, then you can keep them both in the same template
    using the following structure:

    First off you need two infrastructure templates in your TT
    configuration:

    PREPROCESS => [ 'includes.tt' ],
    WARPPER => [ 'layout.tt' ],

    Then in `includes.tt`:

    [% BLOCK sidebar ; END %]

    (Yes, an empty block. It?s there to establish a fallback so you
    can leave it out later.)

    Then you use it in `layout.tt`:

    <html>
    <body>
    <div class"left">
    [% content %]
    </div>
    <div class"right">
    [% INCLUDE sidebar %]
    </div>
    </body>
    </html>

    And now in your `somepage.tt` you can write:

    blah blah blah blah

    [% BLOCK sidebar %]hello world[% END %]

    The `sidebar` block in this template will override the one
    defined in `includes.tt`, and the resulting output will be:

    <html>
    <body>
    <div class"left">
    blah blah blah blah

    </div>
    <div class"right">
    hello world
    </div>
    </body>
    </html>

    This way you can keep all the per-page content in one template
    file, but you can break it down into smaller pieces of content
    that the wrapper template can layout freely.

    --
    *AUTOLOAD=*_;sub _{s/::([^:]*)$/print$1,(",$\/"," ")[defined wantarray]/e;chop;$_}
    &Just->another->Perl->hack;
    #Aristotle Pagaltzis // <http://plasmasturm.org/>
  • Stefan Profanter at Aug 11, 2011 at 2:26 pm
    Hi Aristotele,
    thanks for your answer.
    The solution with the sidebar block seems also a good solution. I will take a loot at it!

    Stefan

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupcatalyst @
categoriescatalyst, perl
postedAug 10, '11 at 7:00p
activeAug 11, '11 at 2:26p
posts7
users5
websitecatalystframework.org
irc#catalyst

People

Translate

site design / logo © 2022 Grokbase