Jump to content

Select from a list of existing pieces of content


Jim Bailie
 Share

Recommended Posts

I'm sure this has been explained numerous times, but I'm struggling trying to find the best way to go about this scenario:

So the user creates a new page and then is able to select from a drop-down, a number of pieces of existing content items that will render in the template in the order selected.

I'm assuming these pieces of content will reside in their own individual, grouped pages without an associated template.

In the main template I would then loop through these selected pages and output as desired.

Link to comment
Share on other sites

Hi @Jim Bailie

I think you can use the Page Reference field. And then loop the page reference field to show the content of the selected page.

For example, I add a Page Reference field named other-page-content.

I can add the following code to my main template

<?php 
	foreach($page->other-page-content as $other-page) {
		echo "<div>";
		echo $other-page->your-content-field;
		echo "</iv>";
}

Hope this help.

Gideon

  • Thanks 1
Link to comment
Share on other sites

For the select dropdown you can use a Page Reference field (e.g. named "content_pieces") with Input field type AsmSelect. This will give you a sortable list of pages:

1586853797_2022-12-02-082902.thumb.png.fcf73f41f7d76499271618689d45e004.png

As for grouping the pages that hold the pieces of content, you have multiple different options to go about. Here just 2 examples:

  • put them under one parent: in content_pieces field settings, under setting "Selectable pages" choose that parent
  • give all pages a checkbox field, named e.g. "content_piece", under setting "Selectable pages"  choose "Selector string" and enter (without quotes) "content_piece=1" 

Now in your template PHP you can loop through and output the desired content. Assuming content is in field named "content":

foreach ($page->content_pieces as $p) echo $p->content;

 

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