Question

I'm set the wrapper on myapp::View::TT.pm

__PACKAGE__->config(
    TEMPLATE_EXTENSION => '.tt2',
    WRAPPER => 'wrapper.tt2',
    INCLUDE_PATH => [ha->path_to('root', 'src'),],
    render_die => 1,
    TIMER => 0,
);

and then create wrapper.tt2 with this content

[% IF no_wrapper; 
        debug("Passing $template.name  without any wrapper");
        content;
    ELSE;
        wrapper = wrapper || 'site_wrapper.tt2';
        debug("Applying $wrapper to $template.name");
        content WRAPPER $wrapper;
    END;
%]

Then, in Admin controller I wrote

sub begin :Private {
    my ($self, $c) = @_;

    $c->stash( wrapper => 'admin/admin_wrapper.tt2');
}

And that works fine.

But in Root Controller I can't set Wrapper and does't have wrapper. I have wrapper site_wrapper.tt2, but I cant use it.

In Root controller I have

sub begin :Private {
    my ($self, $c) = @_;

    $c->stash( wrapper => 'site_wrapper.tt2');
}


    sub index :Path :Args(0) {
        my ( $self, $c ) = @_;

        # Hello World
        $c->response->body( "ok" );
    } 

and thats output only "ok". how can I use wrapper on Root?

Thanks.

Was it helpful?

Solution

By putting something into $c->response->body(), you override any template processing. I don't think there's anything intrinsically wrong with what you're doing as far as the WRAPPER directives are concerned.

OTHER TIPS

Try this one out

    sub index :Path :Args(0) {
    my ( $self, $c ) = @_;

    $c->stash->{'template'}='some/whre/aTemplate.tt2';
    $c->stash->{'message'}="Hello world";
    $c->forward('View::TT') 
}

I think that $c->stash( wrapper => 'site_wrapper.tt2'); is not needed in the begin. Every template that you will create, will include your wrapper once you configure the view.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top