how do i access values assigned to conn via plug
defmodule Broker.SettingsPlug do
def call(conn, _options) do
conn = conn
|> assign(:appname, sitename)
im trying ti access in a page commander via
sitename = Application.get_env(:broker, Broker.Endpoint)[:sitename]
IO.inspect(@conn, label: "PageCommander:customerinfo: sitename")
result is nil
@conn.assigns.appname, when you
assign(conn, :appname, sitename) it puts it on the assign map in the conn, so
@conn.assigns is that map, so just access your key on it via
@conn.assigns.appname if you know it will be on there or via
@conn.assigns[:appname] if it ‘might’ be on there (returns nil if not).
maybe its my implentation what im doing is preloading some environment vars via a plug and trying to access them via a controller not a view ie
sitename = ItemController.fetch_sitename()
def fetch_sitename() do
sitename always == nil
@conn is definitely view syntax, not a controller. If you want to access an assign on a conn in a controller you just
conn.assigns.blah for whatever
blah key is, just take out the
@ from my prior post.
Remember a variable tagged with
@ in a view is a special assigned variable, they do not exist outside of views, use normal variables, I.E. just
conn without the
Something like this is never going to work.
@conn isn’t some instance variable that can be mutated. Conn values cannot be altered in templates.