John_Shelby

John_Shelby

I do not understand how to edit render/2 function after upgrade to Phoenix 1.7

Hi, I upgraded to Phoenix 1.7, but I don’t understand how to adjust the render/2 function in html.heex.

For example, I have these parts of the code.

    <div class="font-weight-bold text-muted">
      <%= if @current_user.role != :basic do %>
        <%= render("filters.html", assigns) %>
      <% end %>
    </div>
    <header class="mb-3 fixed-top" id="loader">
      <%= render("navbar.html", conn: @conn, current_user: @current_user) %>
    </header>

I will currently receive Compilation Error in this format. (undefined function render/2). How do I correctly change the render function?

I found something about it in the documentation(Point 3) and here on Github too.

However, I still do not fully understand how to edit HTML. Should I add something to Controller or HTML.EX file that is now used instead of View?

For example,when I try somthing like <%= filters(assigns) %>, of course, the function will be undefined.

Thanks for any help. Have a nice day. :slight_smile:

Marked As Solved

t0t0

t0t0

Hi,

If filters.html(.heex) is also embedded (embed_templates) by the same module, it should work.

Let’s say the view was called “foo”, the big lines for migrating:

Create lib/my_app_web/controllers/foo_html.ex as:

defmodule MyAppWeb.FooHTML do
    use MyAppWeb, :html

    embed_templates "foo_html/*"
end

Then:

git add lib/my_app_web/controllers/foo_html.ex
git mv lib/my_app_web/templates/foo lib/my_app_web/controllers/foo_html
git rm lib/my_app_web/views/foo_view.ex

And replace lines like <%= render("**name**.html", assigns) %> by <.**name** {assigns}/> or <%= **name**(assigns) %>

Where Next?

Popular in Questions Top

9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
tduccuong
Hi, is there any work on GUI with Elixir, that is similar to Electron/Javascript? My idea is to bundle Phoenix and BEAM into a single se...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New

Other popular topics Top

AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement