ajur58

ajur58

Hey everyone,

I’m trying to do something fairly simple and for some reason I just can’t figure out the answer.

I have the standard layouts structure with layouts.ex using embed_templates and an app.html.heex in the layouts folder. I want to render other partial templates within app.html.heex so that I don’t end up with one giant file, for example _header.html.heex. If I follow the examples in the docs and what I found online, I should use <%= render("_header.html", assigns) %>, but this throws saying “render/2 not defined”

This makes me think that it’s probably due to using embed_templates, but I have no clue where I should look to get started. I’d be more than happy if someone would also point me in the direction of docs that I should’ve read so that I don’t ask stupid questions like this anymore. Thanks!

Showing Posts 1 to 6

ajur58

ajur58 OP

Update: I think I figured it out. There’s something magical that happens when you post a question to the forum :smiley:

Seems like I should’ve read Phoenix.View more thoroughly, on the bottom part there’s a guide talking about migrating fro pre Phoenix 1.7. I should’ve just used <._header />. So far so good. Now I just need to figure out how I can place these partials in a subfolder as I’ll have multiple templates and the folder might get messy.

For anyone in a similar situation, here’s the link to the docs page: Phoenix.View — phoenix_view v2.0.4

Kurisu

Kurisu

I didn’t try this but what about playing with the options of embed_templates.

Maybe something like this…

defmodule DemoWeb.Layouts do
  use DemoWeb, :html

  embed_templates "layouts/**/*"
end

They said in the docs that we can even make multiple calls of embed_templates in the same view module.

Maybe something like this would work as well?

defmodule DemoWeb.Layouts do
  use DemoWeb, :html

  embed_templates "layouts/*"
  embed_templates "layouts/subfolder/*"
  embed_templates "layouts/another_subfolder/*"
end
Kurisu

Kurisu

Another solution would be to name your partials as suggested here.

Kurisu

Kurisu

I just found myself in a situation where I also needed to use “partial templates” and I remembered this post. This solution worked well, but if you need something that is in “assigns” within the partial template, here is one way that I found, for anyone interested.

For example, let’s say the partial is “_menu_user_management” and it needs access to @current_user. Here is how the parent template can pass it on to it:

<._menu_user_management {assigns}>

or like in the link you provided:

<._menu_user_management current_user={@current_user} />

ajur58

ajur58 OP

One week later, I needed exactly this. Works like a charm, thanks for your reply! Gotta love the forums <3

zeugen

zeugen

Thanks for helping me, too. Studying the book Programming Phoenix >= 1.4, I have this code snippet (page 55):

Showing User

<%= render "user.html", user: @user %>

To my friends who are also studying the book, use:

Showing User

<.user user={@user} />

Grateful to @ajur58 for sharing the question and @Kurisu and other friends for answering the question.

Now my code is working.

— All posts loaded —

Where Next? Top

Trending in Questions Top

katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
achenet
Hello, I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind. However, when I launch mix phx.server, I get an error...
New
bradley
I really like the adapter patterns that ecto, nebulex, waffle, etc. use and would love find something similar for a key management servic...
New
unaware8150
Hello folks! So at work, we are seeing some situations where we have to define some “fixed” strings that are used across the codebase in...
New
Cxx-mlr
I’m working on a small exercise involving update_in/3, and I came up with this solution: data = %{ name: "Periodic Table", category:...
New
Alvinkariuki
How Can I Optimise Compile Time Dependencies I have been building an elixir application for about 2 years now. Many modules and files ha...
New
dillonoconnor
Is there any way to avoid the Hologram compiler running when using iex? It seems like the front-end code could potentially be disregarded...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
mudasobwa
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews