View Source Routex.Extension.Assigns (Phoenix Routes Extension Framework v0.3.0-alpha.4)

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 of Routex.Attrs
  • attrs: when set defines keys of Routex.Attrs to make available

Configuration

# file /lib/example_web/routex_backend.ex
defmodule ExampleWeb.RoutexBackend do
  use Routex.Backend,
  extensions: [
+   Routex.Extension.Assigns,
Routex.Extension.AttrGetters
],
+ 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 Routex.Extension.Alternatives to make compile time, branch bound assigns available to components and controllers.