Skip to content

5-Minute Quickstart

This quickstart mirrors the ready-to-copy files in site/modules/Mystique/examples/real-world/.

  1. Create a reusable pricing fieldset (site/templates/configs/fieldsets/charter-pricing.php):

    site/templates/configs/fieldsets/charter-pricing.php
    <?php
    declare(strict_types=1);
    namespace ProcessWire;
    return [
    'title' => __('Charter Pricing', __FILE__),
    'fields' => [
    'weekly_rate' => [
    'label' => __('Weekly Rate', __FILE__),
    'type' => Mystique::FLOAT,
    'columnWidth' => 34,
    'required' => true,
    ],
    'currency_code' => [
    'label' => __('Currency', __FILE__),
    'type' => Mystique::SELECT,
    'options' => [
    'EUR' => 'EUR (€)',
    'USD' => 'USD ($)',
    'GBP' => 'GBP (£)',
    ],
    'defaultValue' => 'EUR',
    'columnWidth' => 33,
    ],
    'deposit_percent' => [
    'label' => __('Deposit (%)', __FILE__),
    'type' => Mystique::INTEGER,
    'defaultValue' => 50,
    'columnWidth' => 33,
    ],
    'vat_included' => [
    'label' => __('VAT Included', __FILE__),
    'type' => Mystique::CHECKBOX,
    ],
    ],
    ];
  2. Create the yacht resource (site/templates/configs/Mystique.yacht-specs.php):

    site/templates/configs/Mystique.yacht-specs.php
    <?php
    declare(strict_types=1);
    namespace ProcessWire;
    return [
    'name' => 'yacht-specs',
    'title' => __('Yacht Specifications', __FILE__),
    'fields' => [
    'headline' => [
    'label' => __('Marketing Headline', __FILE__),
    'type' => Mystique::TEXT,
    'useLanguages' => true,
    'required' => true,
    ],
    'yacht_class' => [
    'label' => __('Yacht Class', __FILE__),
    'type' => Mystique::SELECT,
    'options' => [
    'gulet' => __('Classic Gulet', __FILE__),
    'catamaran' => __('Sailing Catamaran', __FILE__),
    'motoryacht' => __('Motor Yacht', __FILE__),
    ],
    'defaultValue' => 'gulet',
    'columnWidth' => 50,
    ],
    'cabins' => [
    'label' => __('Guest Cabins', __FILE__),
    'type' => Mystique::INTEGER,
    'defaultValue' => 5,
    'columnWidth' => 50,
    ],
    'hero_image' => [
    'label' => __('Hero Photo', __FILE__),
    'type' => Mystique::IMAGE,
    'maxFiles' => 1,
    'extensions' => 'jpg jpeg png webp',
    ],
    'pricing' => [
    'import' => '@fieldset:charter-pricing',
    'type' => 'tab',
    'label' => __('Charter Pricing', __FILE__),
    'prefix' => true,
    ],
    ],
    ];
  3. Create the field and assign it to your yacht template:

    Open Setup -> Fields -> Add New, choose Mystique (FieldtypeMystique), name it yacht_specs, open Input -> Resource, pick Yacht Specifications (templates), save, and add yacht_specs to your yacht template.

  4. Render values and run type-aware selectors in site/templates/yacht.php:

    site/templates/yacht.php
    <?php
    declare(strict_types=1);
    namespace ProcessWire;
    /** @var \Totoglu\Mystique\MystiqueValue $specs */
    $specs = $page->yacht_specs;
    $headline = $sanitizer->entities((string) $specs->getLanguageValue('headline'));
    $classLabel = $specs->optionLabel('yacht_class', (string) $specs->yacht_class);
    $rate = (float) $specs->pricing_weekly_rate;
    $currency = (string) $specs->pricing_currency_code;
    echo "<h1>{$headline}</h1>\n";
    echo "<p>{$classLabel} - {$specs->cabins} cabins - {$rate} {$currency}/week</p>\n";
    if ($specs->hero_image instanceof Pageimage) {
    echo '<img src="' . $sanitizer->entities($specs->hero_image->size(1200, 675)->url) . '" alt="' . $headline . '">';
    }
    // Query matching yachts directly from MySQL JSON
    $gulets = $pages->find(
    'template=yacht, yacht_specs.yacht_class=gulet, yacht_specs.cabins>=4, yacht_specs.pricing_weekly_rate<=25000, limit=20'
    );

    Expected HTML output:

    <h1>Classic Gocek Gulet for 10 Guests</h1>
    <p>Classic Gulet - 5 cabins - 18500 EUR/week</p>
    <img src="/site/assets/files/mystique/1042/yacht_specs/hero_image/aegean-star.1200x675.jpg" alt="Classic Gocek Gulet for 10 Guests">

Next steps