Jump to content

[SOLVED] How to organize repeating content?


howdytom
 Share

Recommended Posts

How do you structure repeating content in ProcessWire without uploading images multiple times? Let’s say I would like reuse an image field multiple times on my front page in various section e.g. in a blog post, within a image slider, image gallery page and also as variation on sub pages. e.g. author box. Since ProcessWire does ship with a media manager, I don’t know how to deal with repeating elements. Currently, I am using a Repeater Matrix. How do you organize fields for editors? Any replies are highly appreciated.

Link to comment
Share on other sites

Hey howdytom,

I’m not sure I fully got your need, but for what I understood (i.e. use the same image in multiple places), I would create a page called media, and add a multiple images field – with maybe a specific text field added to each image, called for instance "role". I would put all the images I use repeatedly here.

I can then call these images anywhere on the front (and in TinyMCE). The role field would allow me to easily filter the images I need.

  • Like 1
Link to comment
Share on other sites

@zoeck Thanks for sharing. A paid module would be okay, unless it is well maintained. A media manager is an essential tool. In case the module support dies, you can’t easily replace it, which is a huge drawback.


@TomPich Thanks. Actually this is how I set things up. It’s okay for a small landing page. It get’s easily messy to collect  images in a media page.

  1.  How do you structure an artist page with repeating images, e.g. a hero image on the front-page, artist profile page with the same image, artwork sub pages and a related article section? I have uploaded the same image multiple to the Repeater Matrix. 
  2. What is best way to implement a partner logo section which is re-used across the site but in different order and combinations? E.g. 5 partner logos are displayed on page A, page B, page C, page D. But on page E and F 2 more partner logos should be displayed, besides the previously uploaded images?

From a content editor point of view, I would like to add or select images to the page I am working on. Ideally re-using a repeater matrix and select an image I do use across my site. Maybe I don’t get ProcessWires Page concept, yet.

Link to comment
Share on other sites

I don't know if this will help you in your case, but I will take your partner example here to demonstrate my way of doing similar things.

Partners wouldn't be content on its own. I see them more like data I can re-use. Therefore I need two templates:

  1. partners (parent for all partner entries - just to group the partner pages)
    Fields: title
    Template file: none
     
  2. partner (single partner page with all the data, content, images)
    Fields: title, desc, image, www, phone, email, ...
    Template file: none

With this setup I can create a RepeaterMatrix block called partners and would add a PageReference field there that allows multiple entries. Probably AsmSelect to be able to sort those entries. Or a selector field to look up (template=partner, sort=random, limit=5)

Now whereever I want to display a set of partners I add that partners block, select my partners and it's done.

There could be multiple blocks for partners in RepeaterMatrix - so the layout can change easily.

  • partnersLogo - just the logo
  • partnersLogoLink - the logo linked to the partners website
  • partnersLogoDesc - partner name and the description
  • partnersCard - full card with logo, name, description, link to website

With this setup I create those partner pages somewhere in the backend and reference those. Would even work in case your partners would be pages on their own.

 

In terms of images I stopped worrying too much.
There are several ways to handle images. For example: Tags.

Tag images with hero, gallery, avatar, or whatever and select images based on your needs. While this works I started using multiple image fields. It's easier (for me) and I can upload optimized images for each use case. AND I can check how many partners don't have a hero image, og:image or gallery images super easy.

  • Like 4
Link to comment
Share on other sites

I too like to organize everything as if templates are classes and pages are instances, and do things as OOP / DRY as possible.

The ArtistProfile (template) could have page reference field in which one Artist (page instance) can be selected. The profile then encapsulates the artist. In order to make grabbing the image easier later down the line, I like to use Page Classes (these are "on" by default these days, I believe). I would add methods to the PageArtistProfile (page class) that returns field values from the Artist it encapsulates. In the ArtistProfile template, I could then do stuff like:

$page->getArtistPortrait();

You can off course add arguments to these methods should you so desire.

Same with the partners. I would just make a big "box" of Partner pages. I would probably make a Partners (plural) page under which to collect them all, so I have "one source of truth".

In order to subsequently use them on other pages, I would just use a Repeater field with a Page Reference field that filters out only Partners. That way an admin can put them in any order they like as Partners are now also encapsulated in the ArtistProfile, just in a plural form.

In my opinion Media Managers tend to be a bit archaic, I prefer to treat media as if they were member values of class instances.

  • Like 1
Link to comment
Share on other sites

On 4/8/2024 at 5:10 PM, howdytom said:

From a content editor point of view, I would like to add or select images to the page I am working on. Ideally re-using a repeater matrix and select an image I do use across my site. Maybe I don’t get ProcessWires Page concept, yet.

RockPageBuilder has the concept of "Widgets". You can turn every "Block" (similar to a repeater matrix element) into a widget with one click. Then on any other page you can add a widget block and select the original item to be displayed.

This is handy for situations where you want to reuse content elements across your site, but want to manage the content at one central place. An example could be a "contact us" element or a "donate now" element where you'd maybe want to display that element on hundreds of pages but want to change the phone number or bank account only once.

A RockPageBuilder block can be text but also just an image field. So having an image block, uploading an image and then turning it into a widget would make the use case that you describe possible. As always this comes with a downside. It would then not be possible to show different versions of that block. All would be 100% identical.

You could build the same concept on your own with RepeaterMatrix as well. After all it's just a page reference field and an some additional logic to not render the reference directly but render the referenced source. Actually that can get quite tricky, but that's another story ? 

So as always in ProcessWire it's up to you how you do what you need and it depends on the exact use case what is the best solution.

There is no one-size-fits-all solution for what you describe and I think as @wbmnfktr mentioned uploading images multiple times might be the most native solution and is often really not bad and comes with other benefits.

  • Like 2
Link to comment
Share on other sites

  • 1 month later...

Thanks to all for your comments and sharing your solution.

@bernhard pretty much summed it up! Thanks

On 4/9/2024 at 6:58 PM, bernhard said:

There is no one-size-fits-all solution for what you describe and I think as @wbmnfktr mentioned uploading images multiple times might be the most native solution and is often really not bad and comes with other benefits.

 

Link to comment
Share on other sites

  • howdytom changed the title to [SOLVED] How to organize repeating content?

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...