Jump to content

Reusable content strategy


GFXmonkey
 Share

Recommended Posts

I have been using Processwire on a few personal sites and recently got a new project at work to redesign our corporate site using Processwire.  I've been diving into the flexibility of PW and I love it especially with things like the Repeater Matrix in ProFields.  I need to build out something pretty flexible for our content team and want to implement a robust system of reusable content.  Essentially our content team wants to be able to build things like Priceboxes and various content chunks and reuse them throughout other pages on the site.  I was thinking this would be a use case for Page Reference fields, but I'm unsure how to go about it as I've found the documentation a bit scare and I'm still getting used to the intricacies of PW.  Is this a good case to use Page References?  How would I go about setting that up and are there perhaps other strategies for reusable content I should consider.  I'd like to keep things as visual as possible for the content team who are generally not very tech savvy.

Thanks.

  • Like 1
Link to comment
Share on other sites

Hi GFXmonkey,

there are many option to do that. Here is very basic example.
1) Eg. outside of main pages tree, create hidden parent page, eg. "Addons" (or "Blocks", "Widgets", or...).
2) Inside "Addons" tree you create and store reusable content (pages) using various templates (eg. slider, text-image, call-to-action, downloads, etc...).

3) Now what you also need is page reference field (eg. name "widgets") on pages inside main tree - to select - pages from "Addons" tree.

How to use this concept?

Example: "Text-Image widget"

1) Inside "Addons", create new page using template "text-image", place some image and insert some text.
2) Go to desired page (where you have page reference field "widgets") and select newly created "text-image widget" (1)

How to render it?
Also many options, but simple can be:

if(count($page->widgets)){
    foreach($page->widgets as $widget){
       // as example widgets templates are in folder "widgets"
       // also this part can be different, find tutorials about ProcessWire render() method...
       include('./widgets/' . $widget->template->name . '.php');
    }
}

Regards.
 

  • Like 3
  • Thanks 1
Link to comment
Share on other sites

Such a setup might now be even more flexible (and even easier) with the use of markup regions. You could populate regions with widgets easily just by doing something like this:

foreach($page->getVisibleWidgets() as $widget) {
  echo WireRenderFile("widgets/{$widget->name}.php", ['page' => $page, 'region' => $widget->region]);
}

And the widget something like that:

<div pw-append="<?= $region ?>">
  my great widget
</div>

Only thing to do would be the user interface for defining the visible pages, I've done that once like this: https://processwire.com/talk/topic/8635-simple-example-for-widget-management/?do=findComment&amp;comment=148216

widget.gif

Would be nice to put that into a module to make it reuseable! And to add a simple API just like $page->getVisibleWidgets(). If you want to sponsor/outsource that just send me PM. If you want to do it on your own I'm happy to share what I have so far and help wherever I can.

Edit: Or maybe just use the selector fieldtype?

  • Like 5
Link to comment
Share on other sites

On 5/30/2018 at 3:11 PM, OLSA said:

Hi GFXmonkey,

there are many option to do that. Here is very basic example.
1) Eg. outside of main pages tree, create hidden parent page, eg. "Addons" (or "Blocks", "Widgets", or...).
2) Inside "Addons" tree you create and store reusable content (pages) using various templates (eg. slider, text-image, call-to-action, downloads, etc...).

3) Now what you also need is page reference field (eg. name "widgets") on pages inside main tree - to select - pages from "Addons" tree.

How to use this concept?

Example: "Text-Image widget"

1) Inside "Addons", create new page using template "text-image", place some image and insert some text.
2) Go to desired page (where you have page reference field "widgets") and select newly created "text-image widget" (1)

How to render it?
Also many options, but simple can be:


if(count($page->widgets)){
    foreach($page->widgets as $widget){
       // as example widgets templates are in folder "widgets"
       // also this part can be different, find tutorials about ProcessWire render() method...
       include('./widgets/' . $widget->template->name . '.php');
    }
}

Regards.
 

Thank you OLSA, your response got me pointed in the right direction and I was able to make this work.  I appreciate the help!

  • Like 1
Link to comment
Share on other sites

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...