[erlang-questions] erlydtl and the template module

Pablo Platt pablo.platt@REDACTED
Wed Oct 28 20:45:52 CET 2009


It is clear now.
Maybe the erlydtl team can add this to the docs.
Thanks




________________________________
From: Zoltan Lajos Kis <kiszl@REDACTED>
To: Pablo Platt <pablo.platt@REDACTED>
Cc: erlang-questions <erlang-questions@REDACTED>
Sent: Wed, October 28, 2009 9:41:50 PM
Subject: Re: [erlang-questions] erlydtl and the template module

Pablo,

I believe that template compiling should only be done once, preferably when bootstrapping your server application.
Alternatively you can compile the templates "by hand" to your ebin directory, and template modules will automatically be loaded when needed.

The point in the behaviour of compile is that this way you can fix or update your templates without needing to restart the server.
If you have templates that you want to use simultaneously, you should compile them into different modules (e.g. welcome and welcome2).

Regards,
Zoltan.


Pablo Platt wrote:
> Hi Zoltan,
> 
> I've tried to compile in the console two different templates welcome1.html and welcome2.html with the same atom:
> erlydtl:compile("/path/to/welcome.html", welcome_template).
> ok
> erlydtl:compile("/path/to/welcome2.html", welcome_template).
> ok
> 
> If the welcome_template module already exists in memory I expected to get an error.
> Does erlydtl replace the welcome_template with a new one? Is this a bug?
> 
> If erlydtl could check that the module already exists and use it instead of recreating it,
> it could increase performance like using output dir because you'll need to compile templates only once.
> 
> Thanks
> 
> ------------------------------------------------------------------------
> *From:* Zoltan Lajos Kis <kiszl@REDACTED>
> *To:* Pablo Platt <pablo.platt@REDACTED>
> *Cc:* erlang-questions <erlang-questions@REDACTED>
> *Sent:* Wed, October 28, 2009 9:17:39 PM
> *Subject:* Re: [erlang-questions] erlydtl and the template module
> 
> Hi Pablo,
> 
> Yes, welcome_template is a module. The call to compile creates a proper Erlang module from your template store.
> You can use it just as you would use any other module. It will be available as long as the Erlang VM is running.
> If you want it to persist, you can pass the outdir option to the compile call, and the module will also be saved as a .beam file.
> See http://code.google.com/p/erlydtl/wiki/Overview for details.
> 
> Regards,
> Zoltan.
> 
> 
> 
> Pablo Platt wrote:
> > Hi,
> >
> > I'm using erlydtl to compile templates for a website http://code.google.com/p/erlydtl/
> >
> > The example on the first page shows how to compile a module:
> > erlydtl:compile("/path/to/welcome.html", welcome_template),
> > welcome_template:render([
> >    {name, "Johnny"},
> >    {friends, [<<"Frankie Lee">>, <<"Judas Priest">>]},
> >    {primes, [1, 2, "3", <<"5">>]}
> > ]).
> >
> > Is welcome_template a module?
> > How long does it exists? until the process that called it terminates?
> >
> > If I have two processes handling two different requests at the same time will each process recreate the welcome_template ?
> >
> > Can I use the atom welcome_template for two different templates with two processes at the same time?
> >
> > Thanks
> >
> >
> >
> >      
> 
> ________________________________________________________________
> erlang-questions mailing list. See http://www.erlang.org/faq.html
> erlang-questions (at) erlang.org<http://erlang.org>
> 
> 


________________________________________________________________
erlang-questions mailing list. See http://www.erlang.org/faq.html
erlang-questions (at) erlang.org


      


More information about the erlang-questions mailing list