2

I found, that erlydtl may be used with nitrogen.

Unfortunately, author hasn't described how he installed erlydtl to make it usable from nitrogen.

Probably somebody has ever faced with the same issue, I'm facing with. If so, please share your experience.

Thank you in advance.

2 Answers2

5

You should be able to just add ErlyDTL to your app's rebar.config:

 {erlydtl, ".*", {git, "git://github.com/erlydtl/erlydtl", {branch, master}}}

Then run ./rebar get-deps compile to install it in lib/ directory of your app and recompile.

Here's the step-by-step instructions

  1. Create a new folder to hold Nitrogen repo:

    • $ mkdir nitrogen-dtl
    • $ cd nitrodgen-dtl
  2. Clone Nitrogen from GitHub:

    • git clone https://github.com/nitrogen/nitrogen.git
    • cd nitrogen
  3. Build a slim (1) or a full (2) release called "dtltest" locateed in nitrogen-dtl folder:

    • make slim_inets PROJECT=dtltest (1)
    • make rel_inets PROJECT=dtltest (2)
  4. Edit rebar.config in dtltest folder:

    • cd ../dtltest
    • vi rebar.config
    • add the ErlyDTL as a dependency (and a comma to the line before it):

       {simple_bridge, ".*",   {git, "git://github.com/nitrogen/simple_bridge",{branch, master}}},
       {nprocreg,      ".*",   {git, "git://github.com/nitrogen/nprocreg",     {branch, master}}},
       {nitrogen_core, ".*",   {git, "git://github.com/nitrogen/nitrogen_core",{branch, master}}},
       {sync,          ".*",   {git, "git://github.com/rustyio/sync",          {branch, master}}},
       {erlydtl,      ".*",   {git, "git://github.com/erlydtl/erlydtl",       {branch, master}}}
      
  5. Download and compile dependencies with rebar:

    • ./rebar get-deps compile
  6. Start Nitrogen console, verify that application is running and try compiling an ErlyDTL template:

    • (dtltest@127.0.0.1)1> erlydtl:compile_template("<html>{{ greeting }}</html>", dtltest_template).
    • (dtltest@127.0.0.1)2> dtltest_template:render([{greeting, "Hallo Welt!"}]).

You should get a rendered template:

{ok,[<<"<html>">>,"Hallo Welt!",<<"</html>">>]}

If the template compiles, then ErlyDTL is installed correctly and you can use the code similar to the Gist you referenced in your application.

Cheers!

Alex Popov
  • 3,726
  • 1
  • 17
  • 20
  • I added this line into nitrogen/rebar.config (nitrogen/site doesn't have one). Then ran 'make' under nitrogen/ directory. The whole nitrogen installation came broken after that. (localhost site @ 8000 became not accessible though) I asked if somebody had had some real experience in using nitrogen with erlydtl. And if he could explain how to do it step by step to get it working together. If you did use nitrogen+erlydtl, please share how to get it working, step by step. – Oleksandr Khryplyvenko Oct 16 '14 at 09:06
  • I ran 'make' instead of ./rebar get-deps compile, because nitrogen uses its own sandbox with all needed app versions installed there(I have global erlang v 17, but current nitrogen uses erlang v16) – Oleksandr Khryplyvenko Oct 16 '14 at 09:14
  • It looks like you are modifying rebar.config in the nitrogen folder. You need to create a project first: run `make rel_inets` or `make slim_inets`. This will create a `my_app` folder with your project (with or without embedded ERTS). cd ../my_app folder and mofigy rebar.config in this folder, not the one that came with nitrogen distribution. Then you need to run rebar command because make doesn't read rebar.config. You can add ErlDTL by hand and then use make, it's easier to use rebar. If it still doesn't work for you please post the error message you see. – Alex Popov Oct 16 '14 at 16:56
  • Your step by step howto helped me to find the issue! The MAIN thing I should have done is to clone nitrogen from git & compile it from sources using system-wide erlang. Instead that, I got lost, because I'd used 2.2.2 binaries osx/cowboy. And there, project is mixed with nitrogen(site/ is directly under nitrogen/ and there is only nitrogen/rebar.config, custom 'sandbox' erlang R16 installation is used). It would be totally non-trivial to get it working. So 'binary' build works out-of-box, but it's hard-to-customize. Moral: use sources:)! Really,@aseidlitz thank you a lot for your help! – Oleksandr Khryplyvenko Oct 16 '14 at 22:09
  • Just to clarify: the code in the Gist is just an example, for performance reasons you will probably want to precompile all your templates and only recompile them if they change. – Alex Popov Oct 27 '14 at 04:05
1

In n2o you don't need to do anything. DTL is already included. All you need is using #dtl element:

main() ->
     #dtl{file = "index",
          app = review,
          bindings = [{body,"Hello"},{title,"Index"}]}.

Also n2o can be run natively on 17.0

Namdak Tönpa
  • 573
  • 3
  • 10