View Source Routex.Extension.Assigns (Routex v1.1.0)

Extracts Routex.Attrs from a route and makes them available in components and controllers with the assigns operator @ (optionally under a namespace).

In combination with...

Other extensions set Routex.Attrs. The attributes an extension sets is listed in it's documentation. To define custom attributes for routes have a look at Routex.Extension.Alternatives

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.AttrGetters, # required
+   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 Routex.Extension.Alternatives to make compile time, branch bound assigns available to components and controllers.