Jump to content

Page select - display content from own page


Peter Knight
 Share

Recommended Posts

Short version:

Can a Page select field be used to select content from itself?

Long version:

A client of mine has a Pages A, B and C and uses a Page select field to pull in content from other pages to a Promo area.

Mostly, this consists of a 

  • thumbnail
  • promo title
  • promo description

and I have it working great assuming those fields on the source page are completed.

The issue I have is sometimes the source of those fields is the actual page. IE On Page A we're not pulling in content from Page A and not sourcing it from Pages B or C.

The "usual" way to do this is of course to fallback to the page API

 <div class="promo-container">
          <img class="promo-image" src="<?=$page->Promo_Image->getThumb('crop-for-promo') ?>" />
          <div class="promo-title"><a href="{$page->url}"><?=$page->Promo_Title ?></a></div>
          <div class="promo-desc"><?=$page->Promo_description ?></div>
 </div>

But I wondered why a Page select field can't output the contents of it's own page.

It'll allow me to select itself but doesn't output anything.

If it helps, here is my code although it's working fine in general.

<!-- START Promo for Innerpages-->
<?php foreach ($page->Promo_Picker->find('limit=1') as $promo){
echo "

<div class=\"promo-container\">
         <a href=\"{$promo->url}\"><img src=\"{$promo->Promo_Image->getThumb('crop-for-promo')}\" /></a>
		  
	<div class=\"promo-title\">
	<a href=\"{$promo->url}\">{$promo->Promo_Title}</a>
	</div>
			  
	<div class=\"promo-desc\">
	{$promo->Promo_description}
	</div>

</div>
"
;}
?>
<!-- END Promo for Innerpages-->
Link to comment
Share on other sites

This has apparently been disabled because the circular reference lead to problems: https://github.com/ryancramerdesign/ProcessWire/issues/663

One possible solution for you would be to default to $page if no page is selected. Seems intuitive enough for the user, unless you need “no selection” to actually mean “no selection”.

Another thing you could do would be to add a “proxy” page somewhere, called “<This Page>”, and check if that was selected, then use $page.

  • Like 5
Link to comment
Share on other sites

Hey Jan

Thanks for the advice.

I decided to separate the Promo fields into their own page templates and made their own hidden folder called "Promo pieces".

Benefits are

1. Client can make a promo piece now with just 3 fields instead of those 3 fields being 3 of 18

2. I've got the Family settings working with the Add New button so client loves being able to login and immediately choose Add New > Promo Item

3. No chance of original error happening

There's a tiny little bit more work for the client and an additional step of having to specify which page the Promo piece should link to but another Page select field makes it as easy as poss.

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