theshank

theshank

Is there any inbuilt functionality for providing template inheritance for eex templates, something like jinja2 has (in the Python world).

PS: this is my first web application in elixir and I am trying to build it without phoenix.

Showing Posts 9 to 1

lud

lud

Unfortunately the blog is not online anymore. Could you tell me the basics of the solution?

Btw I found this : Bash-Shell.Net - Phoenix for Django Devs: The {% block %} Tag

theshank

theshank OP

@amarandon sorry I didnt log into elixirforum for quite some time… Are you still facing this issue?

amarandon

amarandon

I’m interested in this but is it up-to-date? I couldn’t compile it:

warning: variable "assigns" does not exist and is being expanded to "assigns()", please use parentheses to remove the ambiguity or change the variable name                                                        
  vlans.conf.eex:1                                                                                                                                                                                                 
                                                                                                                                                                                                                   
** (CompileError) vlans.conf.eex:2: expected "assigns" to expand to an existing variable or be part of a match                                                                                                     
    (elixir) expanding macro: Kernel.var!/1
    vlans.conf.eex:2: Render.vlans/1
    (elixir) expanding macro: Kernel.<>/2
    vlans.conf.eex:8: Render.vlans/1
    (elixir) expanding macro: Kernel.<>/2
    vlans.conf.eex:8: Render.vlans/1
    (elixir) expanding macro: Kernel.if/2
    vlans.conf.eex:1: Render.vlans/1
themarlzy

themarlzy

Enjoyable read, thanks for sharing. Helps solidify the knowledge of how eex works

theshank

theshank OP

To those who come to this topic, please check out the last portion of this blog post. You can build a solution on those lines.

Thank you @NobbZ for the help.

theshank

theshank OP

Thank you for the pointer, I will write some wrapper functions in line with this and see how it goes.

NobbZ

NobbZ

The easiest might be to simply have an outer template, which has some assign for the inner content, then have many templates for the inner content.

Then roughly do assigns |> render_inner() |> &(Map.puts(assigns, :content, &1)).() |> render_outer().

Yupp, I did not understand anything, except, that the current template shouldn’t know about anything from the outside.

By doing something like your extend you basically couple those templates. Swapping designs on the fly will be a hard thing, while still easily possible with my aproach above.

Also changing the title of the page shouldn’t be done by the inner template. It is meant to just display the data. The “controller” is the entitiy that is aware of the full context, and therefore should assign a title. And only the rendering stage should then decide if a title is needed at all (perhaps we are rendering in a desktop application and do not touch the window title here?)

theshank

theshank OP

The requirement is to have the common parts (like the <html>, <head> etc. ) and then have separate .html.eex files for body contents for various pages (index, about etc.). If its not too much, can you please guide me as to how I should go about this…

Well you are right, not many here will be familiar with it. Basically in the derived templates, you just put a extend "base.html" tag at the top. The library would then inject the base html contents here. Also they have concept of content blocks. So you could define a “navigation” content block inside the <body> tag in base.html and then if you specify that content block in any derived template, it would replace the default contents for that particular content block before generating the final html. I understand I am not making much sense here, so I will stop here :slight_smile:

Yes actually ! I am using Plugs for creating the application. The only reason for not going for Phoenix straight-on is that its code contains a lot of macros and I am not really comfortable reading and then making sense of that much macro code. I see that its a beautifully designed framework but I was hoping of starting small.

NobbZ

NobbZ

Currently not, and I do not think it should be part of it. There are many different ways to compose templates, and currently you can implement a small wrapper around the way you prefer most.

How do they do it? Only a minority of the community has used python and even less will have used that library.

What do you use instead? Pure plugs? Or are you talking HTTP directly? Do you have any reasons for this?

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews