Warning Elixir undefined module attribute @breadcrumb, please remove access to @breadcrumb or explicitly set it before access 13:5
Warning Elixir undefined module attribute @breadcrumb, please remove access to @breadcrumb or explicitly set it before access
Your @breadcrumb is a module attribute, assigned at compile time, you can not use it that way.
I’m currently not using phoenix, but I skimmed the documentation. The argument you named _params is named assigns throughout the documentation, I’m pretty sure that it contains a field :breadcrumb, just look out for it. Logger.debug inspect(assigns) to learn about its structure.
Also, please remember, that you made :breadcrumb a map, you can not modify it using Kernel.++/2. You need to use either the map update syntax (%{foo | bar: :baz}) or use the Map module. Also there is Kernel.put_in/2 and /3 which might help you to update the assigns in a single sweep.
You do… My fault. I simply haven’t seen your squarebrackets… So you are fine with using Kernel.++/2, still the other things I said hold.
Inspect the structure of the second argument to your function, see how :breadcrumbs is saved in there, modifiy it to your needs and then return it.
Remember, you are coding the view, and not a controller, you do not define an action, but specify how to render a certain ressource.
As far as I read it in the Phoenix documentation, you are supposed to have a function render in the view, matching on the resource names, returning a map of assigns, so roughly this should do it:
def render("index.html", assigns = %{breadcrumb: old_bc}) do
%{assigns | breadcrumb: [%{title: "new", link: "breadcrumb"} | old_bc]}
end
Sorry, I misread the docs here and misunderstood some of the JSON examples.
So my first suggestion is to actually try out the docs for yourself, reading them carefully with the context of a project in mind while actively developing in phoenix is a much better point of stand for such stuff.
My second suggestion, after re-skimming the documentation is this:
def render("index.html", assigns = %{breadcrumb: old_bc}) do
render(__MODULE__, "index.html", %{assigns | breadcrumb: [%{title: "new", link: "breadcrumb"} | old_bc]})
end
Also, from your posted error, it seems as if your original value of :breadcrumb is not a list, you should probably fix that one as well.
Also, again, my answers are solely based on what I read in the documentation, I do not work with phoenix currently, I might misunderstand things.
So that render function actually does call the view function again. So you need a function which actually renders the template without calling the function again.
I do fear you need to do so by using EEx functions directly. Or you could open a feature request on the phoenix issue tracker to get a function that allows you what you want to do.
As I do assume you are accessing @breadcrumb from the layouts template, I’m not even sure how one could work around this limitation easily.