budji
Greetings, complete newbie with phoenix/elixir and I’m getting a “assign @conn not available in eex template” error with the following code:
In templates/page
file: index.html.eex
<section class="content">
<%= render "_static-section.html" %>
</section>
file: _static-section.html.eex
<div class="card">
<div class="card-image">
<img src="<%= Routes.static_path(@conn, '/images/calendar.svg') %>" alt="Calendar">
</div>
</div>
The page works when removing the <%= render %> part from index.html.eex, so I’m doing something wrong in the _static-section.html.eex file, I just have no idea what I’m doing.
I’ve also tried: <%= render “_static-section.html”, conn: @conn %> but this one produces a different error altogether.
Here are the controller and view files:
page_controller.ex
defmodule Example.PageController do
use Example, :controller
def index(conn, _params) di
render(conn, "index.html")
end
end
page_view.ex
defmodule Example.PageView do
use Example, :view
end
TIA
EDIT: Sorry the code didn’t render correctly the first time, fixed.
Trending in Questions
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
Hello!
Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app.
I creat...
New
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
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
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
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
apply_graft/2 doesn’t rewrite an add_many sub-workflow’s deps on an add step. Grafted jobs cancel with “upstream job was deleted”
Version...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
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
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
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
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #blog-post
- #ai
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming











Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
idi527
Can you post that error?
Can you also maybe post the contents of
_static-section.html.eex?budji
Yes, the error is:
no function clause matching in Phoenix.Endpoint.Supervisor.static_path/2
I’ve also fixed the code in my initial post which wasn’t rendering correctly, but here’s the _static-section.html.eex
idi527
You have a charlist in your static path, try changing it to a binary.
<%= render "_static-section.html", conn: @conn %>inindex.html.eexshould probably work after that change.budji
Legend! Didn’t know that the quotes would have an effect on the rendering. Thanks.
BTW, if I wanted to say, include the actual SVG code instead of using an
<img>tag, what would be the correct way to go about it? Sort of like in PHP where<?php include "/images/sample.svg"; ?>?idi527
I don’t know if there is any idiomatic approach to working with SVG in phoenix, but if I knew that the image is very unlikely to change I’d do the following:
I’d make a function in my view with the SVG like
This would read the svg at compile time and “persist” it in a function. This way the function just outputs the svg contents (as they were at compile time) any time it is called.
In my EEx templates I’d be able to do the following then:
Another (probably easier) approach would be to turn the svg into an EEx template.
I’d create a new
_sample.svg.eex(orsample_svg.html.eexif the previous one doesn’t work) with the contents ofpriv/static/images/sample.svg(that one could be deleted then, since it’s been replaced by the eex template) and call<%= render "_sample.svg" %>from within my other EEx templates.budji
Ah yes, I’m going with placing the SVG in an html.eex file. Thanks mate.
peerreynders
FYI: Phoenix Inline SVG
bigbassroller
Hey all!
I came across this thread and went down the same path as Budji, but after using the phoenix_inline_svg library and running into issues with its dependencies conflicting with LiveView.
What I ended doing was adding
<%= assigns[:svg_class] %>to the svg’s css class and then was able to assign css classes to the svg dynamically inside Phoenix templates.Works great but it was going to be a pain converting each svg into a eex.html template and adding the
<%= assigns[:svg_class] %>to the svg.So I created a very simple tool do it.
Anyone coming across this thread needing to use svgs icons in their project should check it out!
https://github.com/bigbassroller/modify-svgs
LostKobrakai
Why write new files though? I use the following to parse fontawesome icons into a module, which holds all the icon directly:
bigbassroller
Thats an interesting way of doing it as well. I was running into performance issues with the inline_svg library when loading all bootstrap icons. I wanted to avoid that. I felt having them all be eex templates would prevent any issues in the future. Thats how arrived at my solution.