mix elementorex.gen.source (ElementorexCms v0.2.0)

Copy Markdown View Source

Generates a source of dynamic content (ElementorexCms.Source.Ecto) for an Ecto schema, so the editor can list its records in loops and bind blocks to their fields. The schema can come from mix phx.gen.live, mix phx.gen.schema or a migration written by hand.

$ mix elementorex.gen.source Catalog.Product
$ mix elementorex.gen.source MyApp.Catalog.Product --path "/products/:slug"

The name is the schema module, with or without your app's prefix. It creates lib/my_app_web/sources/products.ex (module MyAppWeb.Sources.Products): the fields are read from the schema at runtime, so a field you add to the schema later (with its migration) shows up in the editor on its own. When the schema has a published-like boolean (or a status with :published), the source only gives published records to your pages.

Then register it:

config :elementorex_cms, sources: [MyAppWeb.Sources.Products]

Options

  • --path - the page of each record, like /products/:slug (offered as Link to the item)
  • --key, --label, --icon - stored key (default: the table), name and Heroicon in the editor
  • --repo - default: the first of your app's :ecto_repos
  • --namespace - default MyAppWeb.Sources
  • --force - overwrite an existing file