SquidWeb.Partial behaviour (squid v0.1.1)

Partials are HTML snippets that squid can render according to their priority. Partials are useful to build navigation elements such as menus from your head app (the one that includes the squid router) by delegating the business logic to other apps.

Quickstart

# in apps/tentacle_a/config/config.exs
config :tentacle_a, :squid,
  partials: %{
    greetings_builder: {TentacleA.Greetings, priority: 1}
  }

# in app/tentacle_a/lib/tentacle_a_web/greetings.ex
defmodule TentacleA.Greetings do
  @behaviour SquidWeb.Partial

  def render(assigns) do
    ~H"""
    <div>Hello <%= @user_name %> from tentacle A</div>
    """
  end
end

# in apps/tentacle_b/config/config.exs
config :tentacle_b, :squid,
  partials: %{
    greetings_builder: {TentacleB.Greetings, priority: 2}
  }

# in app/tentacle_b/lib/tentacle_b_web/greetings.ex
defmodule TentacleB.Greetings do
  @behaviour SquidWeb.Partial

  def render(assigns), do:
    ~H"""
    <div>Hello <%= @user_name %> from tentacle B</div>
    """
  end
end

Then in your page html

<SquidWeb.Partial.render partial={:greetings_builder} user_name="Squid's King" />

This will generate the following html

"""
<div>Hello Squid's King from tentacle B</div>
<div>Hello Squid's King from tentacle A</div>
"""

Priorities

The priority defines the order that your partials must be rendered. Partials with higher priority will be rendered first. A priority could be any interger or float values.

Link to this section Summary

Link to this section Callbacks

Link to this callback

render(assigns)

@callback render(assigns :: map()) :: any()

Link to this section Functions

Link to this function

preload_partials()

Link to this function

render(assigns)