Jump to content

Flexible content


a-ok
 Share

Recommended Posts

Hi folks,

I used to be a big fan of WP, but luckily found ProcessWire and in general it has been so great and super flexible... so thanks for that and all your hard work. It's appreciated. One thing I was a big fan of on WP when using the ACF (Advanced Custom Fields) was the 'Flexible Content' add-on (http://www.advancedcustomfields.com/add-ons/flexible-content-field/) which essentially allowed you to build a series of elements to use (textarea, image etc) then when a user came to build this section on the CMS, they could build a flexible page using those defined elements. So one page might be  textarea, image, image, textarea and another may be image, textarea, image, image, image, textarea etc. They have the fields and they build the order.

Is there anything PW offers in this respect? I was checking out Tables (https://processwire.com/api/modules/profields/table/) but it's quite strict and not that flexible (unless I am missing something!)

Thanks and hope you can help,

R

Link to comment
Share on other sites

Thanks all. Is there any docs on PageTable? I'm struggling to find out what it actually is. My guess is that you create templates with the field you want, so you might have a template for a textfield, and a template for an image. Then you add these templates to the PageTable field and then you can organise and add as many as you want? If so, sounds good. Would be nice to do it with just fields rather than pages of fields.

Thanks so much  :)

Link to comment
Share on other sites

Thanks for your input. I'm still struggling to see how this is similar to the ACF side of things. Why can't it use fields rather than pages. I don't need pages created for a slider to be used on a journal page etc. Do you know what I mean?

Link to comment
Share on other sites

Thanks for your input. I'm still struggling to see how this is similar to the ACF side of things. Why can't it use fields rather than pages. I don't need pages created for a slider to be used on a journal page etc. Do you know what I mean?

but a slide could be a template, where each slide is one page, or the slider could be a template where the slides themselves are repeaters or page table, or images with regular or extended fields. the only way to get the page to be configurable how you want is to use the page table extended

Link to comment
Share on other sites

Thanks all. I worked it out. Below is an example

<?php foreach ($page->flexible_layout as $layout) : ?>

<?php if ($layout->text) : ?>
<div class="row">
<?php echo $layout->text; ?>
</div>
<?php elseif ($layout->image) : ?>
<div class="row">
<?php echo $layout->image; ?>
</div>
<?php elseif ($layout->wide_image) : ?>
<div class="row">
<?php echo $layout->wide_image; ?>
</div>
<?php elseif ($layout->slider) : ?>
<div class="row">
<?php echo $layout->slider; ?>
</div>
<?php endif; ?>

<?php endforeach; ?>
Link to comment
Share on other sites

Each entry in PageTable is a page and can have it's own template file, just like a normal page.

So you can create a template file for each and use the $page->render() to output the markup. Like Martijn's code showed. It's very convenient and flexible reusable.

foreach ($page->table as $row_page) {
     echo $row_page->render();
}

the template file for "text" may just contain

<div class='row'>
    <?php echo $page->body ?>
</div>

And so on.

  • Like 3
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

×
×
  • Create New...