Can you override phoenix templates partials with block supers (like Django)

What is the recommended way to differentiate a HTML block in phoenix templating?

I’ve read the documentation; which draws the following outlines;

  • the root layout is injected by a plug in the router
  • you can optionally set a layout on a route
  • you can optionally set a layout on a view

But is it possible (or otherwise recommended) to override just a template block somehow? For example Django let’s you do things like;

base_template

    {% block header %}
      <%= render "_header.html", assigns %>
    {% endblock %}
    
    {% block content %}
      stuff..
    {% endblock %}

inheriting_view_template

    {% extends "base_template.html" %}

    {% block header %}
      {{ block.super }}
      <p>my super interesting extra header context</p> <-- !
    {% endblock %}
    
    {% block content %}
      stuff..
    {% endblock %}

also on stackoverflow;

Nothing that directly translates. Related techniques you can use to solve similar problems though are:

1 Like