Jump to content

Issue With Page Field Displaying The Title (Multiple Pages (Page Array))


Recommended Posts

I have been transitioning to Page Table from Repeaters for quite some time.  I never had a problem with this transition.  A few weeks ago, I finally figured out how to display a Page Table on the front end of my websites.  Everything worked great.  I believe after upgrading to PW 2.6.2 (not quite sure) when I did the next Page Table I could not get my Page Fields to display any more.

I normally have an "Updates" Page Table that is made up of 3 parts (Date Field, TextArea Field and a Page Field).  Today I created a new installation that had minimal modules and went about structuring my site.  When I got to the "Updates" Page Table, it still would not display the "Contacts" title information.

The field is setup as indicated:


My Contact fields allow for more than 1 person to be listed in the entry.

The following is a screenshot of what I have been getting for over 3 weeks.


Next I added the "Contacts" Page Field directly to the template and changed the _main.php template file to display the field.

$cshcon = $page->crms_show_contact->title;

echo $cshcon;

 I still could not get the Title to display on the Page Field.  I finally ended up changing the setting for the field as follows:


Once I did that, I could get the title to display as it should


Either one of the singular settings worked.  It worked on the singular Page Field, as well as on the Page Table.  As soon as I changed the field setting back to Multiple Pages, it disappeared again.

What caused me the most pain was that whenever I would let the Page Table display the field without the title syntax it would display with the correct Page ID of the particular Page Field.


Github issue opened which references this post

UPDATE:  I was remiss to not include the foreach information:  Thanks, tpr for bringing it to my attention.  It's been a long day already.

$csu = $pages->find("template=crms-updates, crms_status_updates=$page, sort=-crms_start_date");

if ($csu) foreach($page->crms_status_updates as $csu) {
            echo "<strong>{$csu->crms_start_date}</strong>  |";
            echo "  {$csu->crms_comments}  |";
            echo "  {$csu->crms_show_contact->title}";
            echo nl2br("<br />");
Edited by cstevensjr
Updated to show the original foreach loop in _main.php
Link to comment
Share on other sites

If you set the field to be multiple then you should get its values as a (PageArray), that is, using a foreach loop. Your example doesn't tell if you are using a loop or not.

  • Like 1
Link to comment
Share on other sites

I meant another foreach loop.

$csu = $pages->find("template=crms-updates, crms_status_updates=$page, sort=-crms_start_date");

if ($csu) foreach($page->crms_status_updates as $csu) {
	echo "<strong>{$csu->crms_start_date}</strong>  |";
	echo "  {$csu->crms_comments}  |";
	// handle multiple page titles
	foreach($csu->crms_show_contact as $csu_page) {
		echo "  {$csu_page->title}";
	echo nl2br("<br />");

(ps. I recommend leaving the styling part to the CSS (and remove  -es from php)

  • 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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Guy Verville
      I am trying to implement a Repeater Matrix which contains a Page field (there are four fields, an image field, one text field and two page fields). The example given in the readme.txt is self-explanatory. However, this seems not to work with a page field. Say my page field is called "attached_ceramic_skus":
      <?php foreach($page->test_matrix as $item) { echo " <h3>$item->headline</h3> <=works <img... $item->image->url </> <= works foreach ($item->attached_ceramic_skus as $skus)... <= throws an error "; } } } When I debug this line, I see my image and text fields in the $item array, but not the page fields. But these fields are there and working when I enter data. I have understood how they are kept in the database. What is the method/hook to read this type of field?
    • By mikeuk
      (apologies if this looks too similar to previous topic I created, seems more logical as a new topic)
      I'm curious if anyone here is implementing something along the lines of Drupal's block / Joomla's custom (editable) module functionality?
      In other words, areas that are editable in the backend, that can be placed on multiple pages without needing to re-enter the content on each page it is used.
      I tried to do this using a page as a block, and then field type Page (to get a page within a page), but this led to issues with rendering, and more important this creates an object $page->fieldtypePage which is exceptionally large, so I would prefer to avoid that route.
      My guess is those that do it, do it outside of PW with PHP. But the 'blocks' being editable and creatable by a site editor is important so I need to explore this or find a different solution (or tell the client no-can-do).
    • By Matt
      Hello everyone! I recently downloaded ProcessWire and after playing around with it I've found its flexibility and ease of use to be really promising.
      I'm working on a site to publicize upcoming live music events and archive past events at our venue. Each event has the usual start time/end time/price/etc fields and can be associated with any number of bands (usually just one or two). Each band has name/website/description (short bio)/image fields. At the moment I have a page field on my event template allowing each event to be tagged with the required bands, either by choosing existing band pages (for bands which have played at our venue before) or by creating a new band page. I can then reference each band's name/website/description/image in the event template php.
      There are two key ways users will discover events on the public-facing site:
      1) Through the events index page, listing events which can be filtered using dates and keywords
      2) Through the band index page, listing bands whose pages will list past/upcoming events where they have performed.
      However, since:
      a) many bands have gone through minor lineup changes since they started playing at our venue,
      b) many bands have released (and want to promote) new material since they started playing at our venue,
      each band's description and image fields might (but not always) need to vary between events. I would like past event pages to show the band's description/image that was relevant when the event occurred, not the most recent revision. On adding band pages to new events pages, I would like the default description/image to be the most recent version for the band, with the option to replace this with a new description/image if required. It would be unnecessary to provide a new description/image for each band at each event if there were no lineup changes or releases of new material since they last performed.
      My first thought was to have a repeater field for description/image/start time/end time on the band template, where the start and end times help my php template decide which description and image to pair with a particular event. However, the band page field on the events template will not allow me to edit the referenced band page's attributes; it only lets me select band pages and reorder them. If I wanted to update the band description (while preserving the history of previous revisions) I would therefore have to find that band's page elsewhere in the admin then add a repeater row and enter the new description there, keeping the image field blank for that row if the image doesn't need updating. This would require the start time (of the new row) and end time (of the previous row) to be input manually... I'm convinced there must be a simpler way to maintain the links between events and band info.
      My current structure is:
      -- Events Index
      ---- Event 1
      ---- Event 2
      ---- Event 3
      -- Bands Index
      ---- Band 1
      ---- Band 2
      ---- Band 3
      Apologies if I've misused any terminology  Could anyone advise on sensible strategies for achieving this using Core ProcessWire or modules? Thanks!
    • By abdus
      I'm building a website with following page hierarchy
      home/     /blog (template: listing)         /tags (template: tags)             tag1 (template: tag)             tag2             tag3         post1 (template: post)         post2         post3     /development (template: listing)         /tags (template: tags)             tag1 (template: tag)             tag2         post1 (template: post)         post2
      Ok, so I created a Page field to reference tag pages for categorization of posts in different listings. I set up the field to use InputfieldPageAutocomplete module for quickly referencing and creating any number of tags within a post. However, during the setup, Processwire allows me to pick only one parent. I want to change this behaviour such that when searching for a tag, it should only search under its own listing. Specifically, posts under /development should only be able to reference tags under /development/tags and those under /blog should reference tags under /blog/tags etc. Also, when I create a new tag, it should create under its own tags page.
      I don't want to use a tags page under the homepage, because I want the URL structure to be /blog/tags/journal or /dev/tags/processwire etc, not /tags/processwire. I know I can use input()->urlSegments to achieve the url structure I want, and I did it like that in the past, but it felt too hacky to change the paths for pages from their own path in page tree. I tried hooking into InputfieldPage:processInputAddPages method to make the field accept the correct tags page, but I couldnt make it work.
      How can I achieve this?
    • By gebeer
      in a 2.6.22rc1 install I have a page field "workshops" that selects pages via selector "template=workshop,sort=-dat_start,dat_start>=today)".
      The field is in a template "anmeldungen".
      When I edit a page with template "anmeldungen". I can choose pages from the page field "workshops".
      But when I want to save that page, I get an error
      Page 2188 is not valid for workshop (Page 2188 does not match findPagesSelector: template=workshop,sort=-dat_start,dat_start>=today)
      But the workshop I am trying to save to the page field is definitely in the date range >=today. Otherwise it wouldn't be listed in the page field select dropdown.
      The same error is thrown when I change my selector to "template=workshop,sort=-dat_start,dat_start>=2015-11-04".
      Also saving pages through the API to that field doesn't work.
        Only if I omit the dat_start>= selector, I can save pages to the page field.
  • Create New...