selectively using the wrapper

View: New views
9 Messages — Rating Filter:   Alert me  

selectively using the wrapper

by Ascii King :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I want to load a page, but not run it through the wrapper.  Can I shut
off the wrapper or specify different wrappers at different times?

I have read the Catalyst::View::TT doc, but it doesn't mention this.

_______________________________________________
List: Catalyst@...
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@.../
Dev site: http://dev.catalyst.perl.org/

Re: selectively using the wrapper

by Denny-25 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Tue, 2009-09-15 at 17:55 -0400, Ascii King wrote:
> I want to load a page, but not run it through the wrapper.  Can I shut
> off the wrapper or specify different wrappers at different times?
>
> I have read the Catalyst::View::TT doc, but it doesn't mention this.

Someone was nice enough to answer this question for me when I posed it
on the #tt channel on irc.perl.org earlier today, so it would be rude of
me not to pass on the answer:


===== wrapper.tt =====

[% IF template.custom_wrapper;
                PROCESS $template.custom_wrapper;
        ELSIF no_wrapper || template.no_wrapper;
                content;
        ELSE;
                PROCESS 'default_wrapper.tt';
        END
%]


===== a_template.tt =====

[%
  META custom_wrapper = 'alt_wrapper.tt';
  META title = 'Alt Layout';
-%]

<!-- rest of template goes here -->


Add default and alt wrapper templates to flavour  :)

Hope that makes sense!

Regards,
Denny



_______________________________________________
List: Catalyst@...
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@.../
Dev site: http://dev.catalyst.perl.org/

signature.asc (204 bytes) Download Attachment

Re: selectively using the wrapper

by Ascii King :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


> Someone was nice enough to answer this question for me when I posed it
> on the #tt channel on irc.perl.org earlier today, so it would be rude of
> me not to pass on the answer:
>
>
> ===== wrapper.tt =====
>
> [% IF template.custom_wrapper;
> PROCESS $template.custom_wrapper;
> ELSIF no_wrapper || template.no_wrapper;
> content;
> ELSE;
> PROCESS 'default_wrapper.tt';
> END
> %]
>
>
> ===== a_template.tt =====
>
> [%
>   META custom_wrapper = 'alt_wrapper.tt';
>   META title = 'Alt Layout';
> -%]
>
> <!-- rest of template goes here -->
>
>  
Thanks, Denny. that's perfect. Just to complete the question for the
archives, you would call the no_wrapper like this:
$c->stash->{no_wrapper => 1};
$c->stash->{template} = 'account/display_account.tt2';

I don't know how to set the template.custom_wrapper, though. I ended up
just using a variable in the stash called custom_wrapper and then
deleting the 'template.' from the example above.

$c->stash->{custom_wrapper} = 'my_special_wrap.tt2';

_______________________________________________
List: Catalyst@...
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@.../
Dev site: http://dev.catalyst.perl.org/

Re: selectively using the wrapper

by Denny-25 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Wed, 2009-09-16 at 10:20 -0400, Ascii King wrote:

> > [% IF template.custom_wrapper;
> > PROCESS $template.custom_wrapper;
> > ELSIF no_wrapper || template.no_wrapper;
> > content;
> > ELSE;
> > PROCESS 'default_wrapper.tt';
> > END
> > %]
>
> I don't know how to set the template.custom_wrapper, though.
Ah, that was a pure TT solution - to set a template.variable you use
'META variable = ...' in the calling template.

> I ended up just using a variable in the stash called custom_wrapper
> and then deleting the 'template.' from the example above.

Sounds good.



_______________________________________________
List: Catalyst@...
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@.../
Dev site: http://dev.catalyst.perl.org/

signature.asc (204 bytes) Download Attachment

Re: selectively using the wrapper

by Bill Moseley :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message



On Wed, Sep 16, 2009 at 7:20 AM, Ascii King <tech@...> wrote:


[%
 META custom_wrapper = 'alt_wrapper.tt';
 META title = 'Alt Layout';
-%]

<!-- rest of template goes here -->

 

I don't know how to set the template.custom_wrapper, though. I ended up just using a variable in the stash called custom_wrapper and then deleting the 'template.' from the example above.

Just like the example above.
 

$c->stash->{custom_wrapper} = 'my_special_wrap.tt2';

In my mind the wrapper is a view issue, so I set the wrapper in the template not in the controller.  I have a wrapper that is called for *every* page that is used to build the page.

META is compile time, IIRC, so I use [% page.layout = 'foo' %] then in wrapper.tt I have a CASE statement that
sets the wrappers based on page.layout set in the base template.

IIRC, I use page.layout (instead of say just "layout") because WRAPPER does a shallow localization of the stash.

 



--
Bill Moseley
moseley@...

_______________________________________________
List: Catalyst@...
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@.../
Dev site: http://dev.catalyst.perl.org/

Re: selectively using the wrapper

by Ascii King :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Bill Moseley wrote:

>
> In my mind the wrapper is a view issue, so I set the wrapper in the
> template not in the controller.  I have a wrapper that is called for
> *every* page that is used to build the page.
>
> META is compile time, IIRC, so I use [% page.layout = 'foo' %] then in
> wrapper.tt <http://wrapper.tt> I have a CASE statement that
> sets the wrappers based on page.layout set in the base template.
>
> IIRC, I use page.layout (instead of say just "layout") because WRAPPER
> does a shallow localization of the stash.
>

Thanks again, guys.  It took me a few reads to figure out what this
meant, but I'm glad I understand it now. I agree that the wrapper should
be called from the template. I suspect it will make my life a little easier.

_______________________________________________
List: Catalyst@...
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@.../
Dev site: http://dev.catalyst.perl.org/

Re: selectively using the wrapper

by Bill Moseley :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message



On Wed, Sep 16, 2009 at 9:11 AM, Ascii King <tech@...> wrote:
Bill Moseley wrote:

In my mind the wrapper is a view issue, so I set the wrapper in the template not in the controller.  I have a wrapper that is called for *every* page that is used to build the page.

META is compile time, IIRC, so I use [% page.layout = 'foo' %] then in wrapper.tt <http://wrapper.tt> I have a CASE statement that

sets the wrappers based on page.layout set in the base template.

IIRC, I use page.layout (instead of say just "layout") because WRAPPER does a shallow localization of the stash.


Thanks again, guys.  It took me a few reads to figure out what this meant, but I'm glad I understand it now. I agree that the wrapper should be called from the template. I suspect it will make my life a little easier.

Not sure what you mean by "template" there, but maybe this makes it clearer:

 View::TT:
    COMPILE_DIR: __TEMPDIR(templates)__
    WRAPPER: page/wrapper.tt
    PRE_PROCESS: config.tt
    PRE_CHOMP: 0
    POST_CHOMP: 0
    TIMER: 0
    STAT_TTL: 60
    ENCODING: UTF-8

Template Toolkit then will call page/wrapper.tt for template passed to process().  Then the template sets the page.layout and page/wrapper.tt decides how to build the entire page based on that layout.





--
Bill Moseley
moseley@...

_______________________________________________
List: Catalyst@...
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@.../
Dev site: http://dev.catalyst.perl.org/

Re: selectively using the wrapper

by Todd Lyons :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Wed, Sep 16, 2009 at 7:20 AM, Ascii King <tech@...> wrote:
> Thanks, Denny. that's perfect. Just to complete the question for the
> archives, you would call the no_wrapper like this:
> $c->stash->{no_wrapper => 1};

Is this a typo?  Should it be () instead of {} ?  I've never seen
this, but I will experiment with it tomorrow and see what happens when
I try it...

--
Regards...      Todd

_______________________________________________
List: Catalyst@...
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@.../
Dev site: http://dev.catalyst.perl.org/

Re: selectively using the wrapper

by Aristotle Pagaltzis :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

* Todd Lyons <tlyons@...> [2009-09-21 05:45]:
> On Wed, Sep 16, 2009 at 7:20 AM, Ascii King <tech@...> wrote:
> > Thanks, Denny. that's perfect. Just to complete the question
> > for the archives, you would call the no_wrapper like this:
> > $c->stash->{no_wrapper => 1};
>
> Is this a typo?  Should it be () instead of {} ?

Yes. It should be either of the following:

    $c->stash->{no_wrapper} = 1;
    $c->stash( no_wrapper => 1 );

I always prefer the latter.

Regards,
--
Aristotle Pagaltzis // <http://plasmasturm.org/>

_______________________________________________
List: Catalyst@...
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@.../
Dev site: http://dev.catalyst.perl.org/