trigeek381
I’m using Phoenix v1.7.2. I’m using the default index.html.heex for listing records.
My records have a ‘color’ field that I store as a default color. I would like to pass this value to the individual as a background color.
I’ve added this to the table component.
slot :col, required: true do
attr :label, :string
attr :col_class, :string ## My addition
end
... and the table template looks like this
<tr :for={row <- @rows} id={@row_id && @row_id.(row)} class="group hover:bg-zinc-50">
<td
:for={{col, i} <- Enum.with_index(@col)}
phx-click={@row_click && @row_click.(row)}
class={["relative p-0", @row_click && "hover:cursor-pointer", col[:col_class]] <-My edit
>
...
Here is the snippet of the table that I’m trying to modify. Static value works as below
<.table
id="services"
rows={@streams.services}
row_click={fn {_id, service} -> JS.navigate(~p"/services/#{service}") end}
>
<:col :let={{_id, service}} label="Name"><%= service.name %></:col>
<:col :let={{_id, service}} label="Color" col_class="bg-slate-200"><%= service.color %></:col> <- Works
But, I would like to do something like this
<:col :let={{_id, service}} label="Color" col_class={"bg-#{service.color}-200"><%= service.color %></:col>
but I’m getting this error
undefined function service/0 (expected HelloWeb.ServiceLive.Index to define such a function or for it to be imported, but none are available)
Thanks for looking at this
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,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
Hi everyone,
I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding.
I sta...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
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
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
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
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
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
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
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
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
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #hex
- #security










Showing Posts 1 to 7- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
josevalim
The
:letapplies to the body of the tag but not its attributes in case of slots. So for slots, you can’t access the variables you defined on:leton the attributes themselves.BradS2S
I think you can set a global attribute with a default class and then use that on the td.
The documentation includes an example with a default class value set.
trigeek381
Man this is confusing!
Any hint on how I can access the variable in the attributes? I apologize if it’s simple, but I’m still wrapping my head around consuming streams, components and heex.
BradS2S
I think this example fits best:
LostKobrakai
You can‘t.
:let={}is calculated by calling the function component, which passes in all other attributes. So all other attributes need to already exist and that before the value for:let={}is calculated. You‘d need to solve that within a single component/template.trigeek381
Thanks for clarifying that. I started having assumptions this was the case. Now I can rest
ericridgeway
Is there no way to fix this? For example
There we get a variable in the
:forpart but we can still access to it in the other attributesIs there any way
:letcould do this too, or is it just impossible with how things stand?