Plug.Assign
A simple plug to allow setting variables in a connection. For example, as a way to set default variables for a controller, view or template to use in a Phoenix app.
Installation
The package can be installed from Hex:
Add plug_assign to your list of dependencies in mix.exs:
def deps do
[{:plug_assign, "~> 1.0.0"}]
endFetch and install the dependencies
$ mix deps.getDefine assigns as part of your plug stack
plug Plug.Assign, foo: "bar", bar: true, baz: 42Or Set variables for templates to use in a Phoenix Pipeline
pipeline :admin do
plug Plug.Assign, admin: true
endOr directly in a Phoenix Controller
defmodule Blog.Admin.PostController do
use Blog.Web, :Controller
plug Plug.Assign, subsection: :posts
plug Plug.Assign, %{read_request: true} when action in [:index, :show]
...
endGenerate documentation
mix docs