Moving static templates from django to nitrogen?

8 views
Skip to first unread message

pwang...@gmail.com

unread,
Mar 22, 2021, 11:37:13 AMMar 22
to Nitrogen Project / The Nitrogen Web Framework for Erlang
Hi there,

We have a project written in Python Django am are planning to migrate it to nitrogen.. 
The current project is written in Django and has lot of html sections with code between the html. I am wondering what is the best way to do the same in Nitrogen? 

Do I need to rewrite the whole html using nitrogen elements OR can i just put in the static html and use elements for form inputs?

Appreciate your help.

Regards,
Phunsukh

Bunny Lushington

unread,
Mar 23, 2021, 1:04:40 PMMar 23
to nitro...@googlegroups.com
On Mar 22, 2021, at 10:37, pwang...@gmail.com <pwang...@gmail.com> wrote:

We have a project written in Python Django am are planning to migrate it to nitrogen.. 

Do I need to rewrite the whole html using nitrogen elements OR can i just put in the static html and use elements for form inputs?


Lord no.  Check out erlydtl [1] if you haven’t already.  It’s pretty straightforward to render your erlydtl template and pass it into the 

  #template{ text=RenderedTemplate } Nitrogen element.  

If you do this, sections like [[[page:make_button(button_type)]]] are then rendered through the Nitrogen engine (so erlydtl is producing a Nitrogen template, not an HTML page).  make_button/1 then returns a #button{} with appropriate attributes.

Form elements just need to have the correct class.  So if you’re calling wf:q(email_address) you’ll want to give your textbox input the class wfid_email_address in your DTL file.

Note that the text field of the template record is relatively new; I think you’ll have to pull from master to make use of it.  Also, I do this enough that I recently made a little helper library to work with the DTL templates. [2]

None of this is to cast shade on Nitrogen’s HTML generating ability.  There are benefits to DTL and Nitrogen, a hybrid approach works really well for me.  (And honestly, make Bootstrap easier to work with.)

b.

Reply all
Reply to author
Forward
0 new messages