Skip to content

Allow setting specific views/layout to AutoPage #772

Open
@xsawyerx

Description

@xsawyerx

If you want to mount two applications that will share the same templates and layouts, it's trivial: you just mount them together, they will use the same appdir and it will work.

However, since the paths are now ignoring the mounted bits, you will have to include those in your code:

package MyApp {
    use Dancer2;
    get '/' => sub { template 'index' => {...} };
}

package MyApp::Extra {
    use Dancer2;
    get '/' => sub { template 'extra/index' => {...} };
}

# app.pl:
package main {
    use MyApp;
    use MyApp::Extra;
    use Plack::Builder;
    builder {
        mount '/'      => MyApp->to_app;
        mount '/extra' => MyApp::Extra->to_app;
    };
}

This makes sense because you're basically saying "this application has templates elsewhere in this inner directory."

However, when you're using the AutoPage, it will not know about this special directory, and because it will rightfully ignore the mounting point, you won't be able to render your templates.

You can go nuts and call use MyApp::Extra with => { views => '/path/to/appdir/views/extra' } but it will not use the layout. It will now expect you to provide /path/to/appdir/views/extra/layouts, which makes sense (allowing you to provide multiple views directories across apps in the same appdir.

The way to fix it, IMHO, is to provide another configuration, called auto_page_views, which says "when using AutoPage feature, serve files from this directory". It will look like this:

set auto_page_views => 'extra';
# now AutoPage uses the same layout but the templates come from inside extra/ directory

We can also have auto_page_layout to allow you to make sure AutoPage will always serve with a specific layout.

What do you think?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions