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

Copy Markdown View Source

Generates a filter block: a field of the Filters form (the search and filters visitors use on a loop grid) written by you, and its test.

$ mix elementorex.gen.filter PriceRanges

Creates lib/my_app_web/blocks/price_ranges.ex (module MyAppWeb.Blocks.PriceRanges) and its test: a list of ranges written in the editor (Under 20.000, 20.000 to 50.000…) that visitors pick with radio buttons. Change its markup at will; what makes it a filter is the name and value of its inputs (see ElementorexCms.Filters):

  • filter_name(assigns, @field) - catalog[price], one value
  • filter_name(assigns, [@field, ""]) - catalog[price][], several
  • filter_name(assigns, [@field, "min"]) - a bound of a range
  • values like "20000..50000" are ranges of number and date fields
  • filter_value/2, filter_checked?/3 and filter_options/2 read the visitor's choice and the values of the field

Logic that a field cannot express (In stock is stock > 0) goes in the source: see filters: in ElementorexCms.Source.Ecto.

Register it afterwards:

config :elementorex_cms, blocks: [MyAppWeb.Blocks.PriceRanges]

Options

  • --type, --label, --icon - stored type, name in the palette and its Heroicon (default funnel)
  • --namespace - default MyAppWeb.Blocks
  • --no-test, --force