ElementorexCms.Templates behaviour (ElementorexCms v0.1.0)

Copy Markdown View Source

Ready-made sections the editor can insert (Templates panel).

Add your own with a module that implements this behaviour and list it in the config (or pass templates={...} to the editor):

defmodule MyApp.EditorTemplates do
  @behaviour ElementorexCms.Templates
  import ElementorexCms.Builder

  @impl true
  def templates do
    [
      %{
        key: "promo",
        label: "Promotion",
        description: "Headline, countdown and button",
        icon: "megaphone",
        nodes: fn -> [block("heading", %{text: "Black Friday"}), block("countdown")] end
      }
    ]
  end
end

config :elementorex_cms, templates: [MyApp.EditorTemplates]

nodes is a function so every insertion gets fresh ids.

Summary

Callbacks

Templates offered by the module.

Functions

Built-in templates followed by the configured ones.

The built-in templates.

The template with key, or nil.

Types

template()

@type template() :: %{
  :key => String.t(),
  :label => String.t(),
  :nodes => (-> [map()]),
  optional(:description) => String.t(),
  optional(:icon) => String.t()
}

Callbacks

templates()

@callback templates() :: [template()]

Templates offered by the module.

Functions

all(modules \\ nil)

@spec all([module()] | nil) :: [template()]

Built-in templates followed by the configured ones.

builtin()

@spec builtin() :: [template()]

The built-in templates.

get(key, modules \\ nil)

@spec get(String.t(), [module()] | nil) :: template() | nil

The template with key, or nil.