# `ElementorexCms.Templates`
[🔗](https://github.com/rocket4ce/elementorex_cms/blob/v0.1.0/lib/elementorex_cms/templates.ex#L1)

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.

# `template`

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

# `templates`

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

Templates offered by the module.

# `all`

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

Built-in templates followed by the configured ones.

# `builtin`

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

The built-in templates.

# `get`

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

The template with `key`, or `nil`.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
