Making blocks
Prodigy relies on blocks – which are just blade components with some extra magic in the background. If you know how to make blade components, you can use Prodigy like a pro. 🤯
Creating the component
Creating a new component is wildly simple. Inside of /views/components/blocks
you can put as many components as you want, and they'll be automatically registered for use inside Prodigy. Let's use an example from this page called content-section
, which handles showing the title and body text on this page.
<x-blocks.docs.header :text="$header ?? ''" />
{!! $body ?? '' !!}
Enable editable fields
Each block can – optionally – define a schema by including a yaml file. So…
-
content-section.blade.php
<< template -
content-section.yml
<< schema
The editable fields get automatically delivered to the template, so if you define a header
in the schema, you can use $header
in the template.
Note: Blade requires camelCasing, so a field called background_color
would get used as $backgroundColor
in the template.
Below is a sample schema…
fields:
header:
type: text
rules: required # This uses Laravel's rules engine. Pipe in as many rules here as you would like.
body:
type: texteditor
Rules
Each field can have a rules
property which uses Laravel's extraordinary validation system. Any validation rule from Laravel is available, which means you have a ton of control over what data is entered by the content creator.
Conditionally show fields with show
Sometimes, you may want a field to depend on another field. For example, you could have a link_type
dropdown that determines whether a link should be shown on the page. In this case, you would do show: link_type:url
on the child fields. The editor will automatically handle showing and hiding fields. Note: the conditional logic depends on the slugified content, so “URL” becomes “url”
You can also do:
show: columns:gt:3
show: columns:gte:3
show: columns:lt:3
show: columns:lte:3
fields:
link_type:
type: dropdown
label: Link
options:
- None
- Url
link:
type: link
show: link_type:url
link_label:
type: text
show: link_type:url