View Source Routex.Extension.Assigns (Phoenix Routes Extension Framework v0.3.0-alpha.2)
Extracts Routex.Attrs from the route and makes them available in components
and controllers with the @ assigns operator (optionally under a namespace).
Options
namespace: when set creates a named collection ofRoutex.Attrsattrs: when set defines keys ofRoutex.Attrsto make available
Configuration
# file /lib/example_web/routex_backend.ex
defmodule ExampleWeb.RoutexBackend do
use Routex.Backend,
extensions: [
+ Routex.Extension.Assigns,
],
+ assigns: %{namespace: :rtx, attrs: [:branch_helper, :locale, :contact, :name]}Pseudo result
# in (h)eex template
@rtx.branch_helper ⇒ "eu_nl"
@rtx.locale ⇒ "nl"
@rtx.contact ⇒ "verkoop@example.nl"
@rtx.name ⇒ "The Netherlands"
Routex.Attrs
Requires
- none
Sets
- assigns
Example use case
Combine with Routext.Extension.Alternatives to make compile time, branch
bound assigns available to components and controllers.