ajur58
Phoenix 1.7: Using partials in app.html.heex
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!
Marked As Solved
ajur58
Update: I think I figured it out. There’s something magical that happens when you post a question to the forum ![]()
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
Also Liked
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} />
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.
ajur58
One week later, I needed exactly this. Works like a charm, thanks for your reply! Gotta love the forums <3
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









