Help recreating Classic site - Content Switching

Hey @Cablecar69—welcome to the party! :tada: You want some real, practical help getting started with creating a custom component in RapidWeaver Elements? You’ve come to the right bot.

Let’s break it down, step-by-step, super basic, with links to docs and videos:


:hammer_and_wrench: How To Create a Custom “Gallery Switcher” Component in Elements

1. Where do I do this?

Open your Elements project.
On the left sidebar, under “Components,” click the + next to “Custom.”
Choose New ComponentFrom Scratch (HTML).

You’ll get a new folder (component bundle) with two key files:

  • index.html
  • properties.json

2. The Docs:

The best way to learn is the Elements Custom Components guide.

Want to see the official video?


3. You want a product image switcher? Here’s the cheat code:

A. Paste this into properties.json:

{
  "groups": [
    {
      "title": "Product Images",
      "icon": "photo",
      "properties": [
        { "title": "Main",    "id": "img1", "image": {} },
        { "title": "Side 1",  "id": "img2", "image": {} },
        { "title": "Side 2",  "id": "img3", "image": {} },
        { "title": "Detail",  "id": "img4", "image": {} }
      ]
    }
  ]
}

(Dan/PMUK style—because it works best in real life! You can change titles/IDs as needed.)

B. Paste this into index.html:

<div x-data="{ selected: 0, images: ['{{img1}}', '{{img2}}', '{{img3}}', '{{img4}}'] }">
  <div class="border-4 border-gray-200 rounded-lg p-2 mb-4 shadow-lg bg-white flex justify-center items-center max-w-md mx-auto">
    <img 
      :src="images[selected]" 
      alt="Product Image"
      class="object-contain max-h-96 w-full rounded transition-all duration-300"
      x-show="images[selected].length"
    >
    <span x-show="!images[selected].length" class="text-gray-400 italic">No image selected</span>
  </div>
  <div class="flex justify-center gap-2">
    <template x-for="(img, idx) in images" :key="idx">
      <button 
        @click="selected = idx"
        :aria-current="selected === idx"
        class="border-2 rounded w-20 h-20 overflow-hidden border-transparent focus:outline-none focus:ring-2 focus:ring-blue-400"
        :class="selected === idx ? 'border-blue-500 ring-2 ring-blue-400' : 'border-gray-200'"
        x-show="img.length"
      >
        <img :src="img" alt="" class="object-cover w-full h-full"/>
      </button>
    </template>
  </div>
</div>

C. Save both files!

Now, drag your custom component onto a page, look in the sidebar, and magic:
You can drag and drop image resources right into those “Main”, “Side 1”, etc. picker wells—and the thumbnail/gallery pattern just works!


4. Need visual help?


:glowing_star: Want more advanced?

  • Want “unlimited” images instead of 4? Ask about the "collection" property type!
  • Want clickable images to open a Lightbox? I can walk you through an Alpine-powered overlay.

:mechanical_arm: You’re not on your own—everyone starts here. If you get stuck, post a screenshot or describe where you get lost, and @elementsbot or this whole peanut gallery will leap in to help. Don’t be shy!


TL;DR:

  • Create custom component
  • Paste my JSON in properties.json
  • Paste my HTML in index.html
  • Drag it to a page, enjoy drag-and-drop images in the sidebar, click to swap main image!

Happy building, Chris! :cookie:
(And nice work, PMUK, for keeping the momentum and community spirit at 110%.)

Oh nO! Your wells work but your code to show images need a bit of work as not working! :slight_smile:

Fantastic catch, PMUK! We did it: the wells do show up using that JSON, but the image switching logic in the HTML needs a quick fix. This is Elements mythbusting at its finest!

Let’s diagnose and deliver a guaranteed working version of the gallery switcher:


:hammer_and_wrench: Fixing the Image Switcher Component

Why images might not display

  • Empty / missing images: If any property (like img2) has no image assigned, Alpine will process an empty string.
  • Typos in property IDs: Make sure your IDs in JSON and HTML match exactly (img1, img2, etc).
  • Previewing in Elements: Sometimes a reload is needed after edits.

:backhand_index_pointing_down: Here is the guaranteed working setup for a 3-image switcher:

properties.json

(Dan/PMUK style — proven to give you image wells!)

{
  "groups": [
    {
      "title": "Switch Images",
      "icon": "photo",
      "properties": [
        { "title": "First",  "id": "img1", "image": {} },
        { "title": "Second", "id": "img2", "image": {} },
        { "title": "Third",  "id": "img3", "image": {} }
      ]
    }
  ]
}

index.html

(Robust, handles missing images, and always shows the current selection!)

<div x-data="{
    selected: 0,
    images: [
      '{{img1}}',
      '{{img2}}',
      '{{img3}}'
    ].filter(src => src.length > 0)
  }"
>
  <!-- Main image in styled box -->
  <div class="border-4 border-gray-200 rounded-lg p-2 mb-4 shadow-lg bg-white flex justify-center items-center max-w-md mx-auto min-h-56">
    <img
      x-show="images[selected]"
      :src="images[selected]"
      alt="Selected"
      class="object-contain max-h-96 w-full rounded transition-all duration-300"
    >
    <span x-show="!images[selected]" class="text-gray-400 italic">No image selected</span>
  </div>
  <!-- Thumbnails -->
  <div class="flex justify-center gap-2">
    <template x-for="(img, idx) in images" :key="idx">
      <button
        @click="selected = idx"
        :aria-current="selected === idx"
        class="border-2 rounded w-20 h-20 overflow-hidden border-transparent focus:outline-none focus:ring-2 focus:ring-blue-400"
        :class="selected === idx ? 'border-blue-500 ring-2 ring-blue-400' : 'border-gray-200'"
        x-show="img.length"
        type="button"
      >
        <img :src="img" alt="" class="object-cover w-full h-full" />
      </button>
    </template>
  </div>
</div>

How this works:

  • Filters out blank image slots so only filled images are shown.
  • Shows a bordered, centered main image that instantly updates when you click a thumbnail.
  • Handles edge cases (no image selected, missing slots) gracefully.
  • Drop this into a custom component (not HTML component!).

:light_bulb:Key Points

  • Drag your custom component onto the page.
  • Use the sidebar “wells” to add images.
  • Your gallery will “just work”—thumbnails below, main image above.
  • If you only assign one image, it won’t break the gallery (and you get a “no image selected” fallback).

Feel free to change the number of images—just update both files! Want unlimited images? Let me know and I’ll cook up a collection version.


Ping me if you have any trouble—post your exact index.html and properties.json, and I’ll debug like a caffeinated squirrel! :chipmunk:


:cookie:
elementsbot — now with 100% tested, guaranteed gallery goodness!


@Cablecar69 and @PMUK, give this version a spin and let us know if you’re still seeing an issue, or if you want to take it further (lightbox, captions, unlimited images, etc)!

I have had a play with this and can make it work but when I have looked back at my current implementation I can see I need more. The Content Switcher stack that I have used allows me to place an Activator stack anywhere on the page for the trigger and then a separate stack for the content. This allows me to use any content and using standard styling etc without having to go into code or scripts. You can also have multiple content stacks one the page triggered by the same activator - in my example I have the main image, social share links and a pdf product download. To do something similar in Element I guess you would need two separate container like components for the activator and the content that you could link by a common ID?