Available fields

There are many fields available out of the box which can be used in any schema – whether it's being used in a block or for a CMS entry. You can customize Prodigy to add your own fields if you need. Below is a list of all default fields.

type: boolean

Renders a “true false” checkbox. You can use special properties label_for_true: Visible and label_for_false: Hidden to change what the label says when true or false are selected. Also, it's possible to set default:true to make it default to true.

 

type: code

Renders a code block which can be used for a number of different things – you could use it to literally run code on your page, or for when you just need some complicated HTML. Personally, I prefer using the code editor to a WYSWIYG in many cases. The code editor needs to use the unescaped output, so you would do {!! $code_block ?? ‘’ !!}. As far as security is concerned, if any untrusted person gets access to your Prodigy backend, it becomes trivial for them to use this to inject their own code when using a code block. This risk is inherent in any CMS which allows direct code entry, but it's a bit different from Laravel's default security approach.

 

type: color

Renders a color picker and returns a hex value.

 

type: dropdown

Renders a select menu and returns the chosen select value. Select options use the str()→slug() method for their values, so Optional Value becomes optional-value.  A sample schema looks like this:

fields:
  show_on_page:
    type: dropdown
    label: Show on Page
    default: show
    options:
      - Show
      - Hide

type: group

The group accepts a series of child fields, and can be set to automatically expand or not. The most common example of a group is the “Spacing / Visibility” group which is attached to all blocks. An example from that schema is below.

page-schema.yml
fields:
  spacing_group:
    type: group
    expanded: false
    label: Spacing / Visibility
    fields:
      margin:
        width: 50
        type: pixelgroup
      // more fields...

type: image

Accepts an image and returns it an uncompressed version from the Spatie media library. Access the image in the template by the following:

{{ $block->getFirstMediaUrl('prodigy') }}

If you have multiple images attached to the same block, use:

$media = $block->getFirstMedia('prodigy', ['key' => ‘INSERT_FIELD_NAME’])

where INSERT_FIELD_NAME is whatever you named your field in the schema. Then render the image with

$media→getFirstMediaUrl()

type: link

Renders a text field to put a link, and then returns that link URL. This is (at present) a total cheat. In order to make the websites portable, they need to use relative URLs. But it's tough to validate relative URLs, so it's just a regular text field right now.

 

type: menu

Renders a menu builder and returns that menu as an array that contains url, title, css_classes for each item. At this moment, nesting menus is not possible (though it's on the roadmap).

sample menu code
@if(isset($content['menu']))
    @foreach($content['menu'] as $item)
       <a href="{{ $item['url'] }}"
          class="text-gray-700 {{ $item['css_classes'] ??'' }}">
            {{ $item['title'] }}
      </a>
    @endforeach
@endif

type: numberwithunit

Renders two fields – one for the value and the other for the unit attached to that value. This is especially important for HTML spacing and sizing properties. For example, in the Content grid, you can adjust the gap in between items using this schema:

content-grid.yml
fields: 
  gap:
    label: Gap between Columns
    type: numberwithunit
    width: 50
    options:
      - 'px'
      - 'rem'
      - '%'
      - 'vw'
content-grid.blade.php
// Then process the value like this:
@php
    $gap = $gap_value ?? 0;
    $gap .= $gap_unit ?? 'px';
@endphp

type: pixelgroup

This is used for margin and spacing in pixels. This is basically only useful for the spacing / visibility classes attached to each block.

 

type: range

Used for defining a range slider. Accepts min, max, and step values.

 

type: repeater

Renders a UI for creating multiple instances of a repeater block. Extremely useful for situations where fields repeat over and over. It gets used for the content-grid default block. A couple rules when making repeaters:

  • it must be called repeater
  • there can only be one per block.
content-grid.yml
fields:
  repeater:
    type: repeater
    label: Grid Items
    fields:
      photo:
        type: image
      // more fields

Repeater items are child blocks unto themselves, which means they must be queried. 

They can be displayed using a @forelse. Don't use @foreach because an empty list will cause a server error.

The $child_block is literally it's own block, so you access the Prodigy content by  $child_block→content['field_key']

Prodigy stores it's dynamic data in a JSON field called content. In most cases, Prodigy can “unwrap” the fields as variables directly within blade, so you can define a text field as use it as $text. Since we're querying and displaying the data ourselves, we manually pull the content field. Also, since any field can be undefined at any time, adding the null coalescing operator ?? ‘’ is important.

content-grid.blade.php
 @forelse ($block->children as $child_block)
   @if($child_block->content)
     <h3 class="">
        {{ $child_block->content['title'] ?? '' }}
     </h3>
   @endif
 @empty
 @endforelse

type: text

Renders a single-line input and returns the text. If you want more space, add multiline: true as an option.

 

type: texteditor

Renders a WYSIWYG input and returns the HTML. You can render it as {!! $text ?? ‘’ !!} in order to get the unescaped content.