templates/layouts with no file extension?

117 views
Skip to first unread message

Gary

unread,
Mar 27, 2012, 8:09:38 PM3/27/12
to Mojolicious
hello,

How can I avoid mojolicious automatically assuming my templates and
layouts have the extension ".html.ep"?

At the moment I have to manually read the files, then render them
inline in order for this to work. Is there a better way?

thank you

Robert Stockdale

unread,
Mar 27, 2012, 8:20:01 PM3/27/12
to mojol...@googlegroups.com
I think you may be looking for these:

    $renderer->add_handler(epl => sub {...});
    $renderer->default_handler('ep');


Example using TT




--
You received this message because you are subscribed to the Google Groups "Mojolicious" group.
To post to this group, send email to mojol...@googlegroups.com.
To unsubscribe from this group, send email to mojolicious...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/mojolicious?hl=en.




--
Bob Stockdale
robert.s...@gmail.com

Gary

unread,
Mar 27, 2012, 9:49:48 PM3/27/12
to Mojolicious
thanks for replying, though I don't think I asked the question
clearly...

I'm trying to avoid adding any extension at all to the template and
layout file names (.format.handler), not just changing the format or
handler..

reading the file manually and then rendering inline works, but is an
ugly workaround. I was hoping for a nicer solution.

On Mar 27, 5:20 pm, Robert Stockdale <robert.stockd...@gmail.com>
wrote:
> I think you may be looking for these:
>
>     $renderer->add_handler(epl => sub {...});
>     $renderer->default_handler('ep');
>
> http://mojolicio.us/perldoc/Mojolicious/Renderer#default_handler
>
> Example using TT
>
> http://my.opera.com/cstrep/blog/2011/08/01/using-template-toolkit-wit...
>
>
>
>
>
>
>
>
>
> On Tue, Mar 27, 2012 at 8:09 PM, Gary <garyj...@gmail.com> wrote:
> > hello,
>
> > How can I avoid mojolicious automatically assuming my templates and
> > layouts have the extension ".html.ep"?
>
> > At the moment I have to manually read the files, then render them
> > inline in order for this to work. Is there a better way?
>
> > thank you
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Mojolicious" group.
> > To post to this group, send email to mojol...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > mojolicious...@googlegroups.com.
> > For more options, visit this group at
> >http://groups.google.com/group/mojolicious?hl=en.
>
> --
> Bob Stockdale
> robert.stockd...@gmail.com

Sebastian Riedel

unread,
Mar 27, 2012, 9:52:42 PM3/27/12
to mojol...@googlegroups.com
> I'm trying to avoid adding any extension at all to the template and
> layout file names (.format.handler), not just changing the format or
> handler..


The renderer relies heavily on double extensions, you would have to hack it and make your code incompatible with plugins i'm afraid.

--
Sebastian Riedel
http://twitter.com/kraih
http://mojolicio.us

sri

unread,
Mar 27, 2012, 10:21:18 PM3/27/12
to mojol...@googlegroups.com

The renderer relies heavily on double extensions, you would have to hack it and make your code incompatible with plugins i'm afraid.


You could perhaps also get away with custom handlers, but it's rather hackish.


--
sebastian

Skye Shaw!@#$

unread,
Mar 29, 2012, 3:45:58 AM3/29/12
to mojol...@googlegroups.com
I'm trying to avoid adding any extension at all to the template and
layout file names (.format.handler), not just changing the format or
handler..

I had the same problem yesterday when trying to include some mustache templates. 
 
reading the file manually and then rendering inline works, but is an
ugly workaround. I was hoping for a nicer solution.

I was going to package up a nicer solution:


but I chickened out and just tacked on a 'html.ep'. 

sri: Any reason not to render static partials? Is a custom handler the right solution for something that can require no server side preprocessing, e.g., mustache template? 

-Skye




Gary

unread,
Mar 30, 2012, 12:17:04 PM3/30/12
to Mojolicious
Thanks all for the comments...

I think I'm going to stick with manually reading then rendering inline
for templates/layouts that have no extension (or an arbitrary one).

jamadam

unread,
Apr 4, 2012, 9:22:26 AM4/4/12
to mojol...@googlegroups.com
Hi. I've been having related distress.

Adobe Dreamweaver can't handle .html.ep as html so
I've wanted to rename them into .ep.html style.
To achive this, I've started to use a plugin.

https://github.com/jamadam/Mojolicious-Plugin-TemplateNameRule

The plugin relies on very evil hack but works for now.

Sebastian Riedel

unread,
Apr 4, 2012, 10:04:42 AM4/4/12
to mojol...@googlegroups.com
> https://github.com/jamadam/Mojolicious-Plugin-TemplateNameRule
>
> The plugin relies on very evil hack but works for now.

The big problem with these kinds of hacks is that they break all plugins that bundle templates, which i hope will be a lot in the future.

jamadam

unread,
Apr 4, 2012, 11:01:31 AM4/4/12
to mojol...@googlegroups.com
I see.
Maybe my plugin can limit the extent of the impact
into specific path out of renderer->paths
 ... by extra hack on template_path ... hnn, it's too dirty.

Reply all
Reply to author
Forward
0 new messages