Jump to content
Sign in to follow this  

Dynamic/Selector Fields and Page creation layouts

Recommended Posts

This is 2 questions in one post; I hope that's permissable.

1:  I'm trying to find a way to create a field whose value is a selector query, and at page time the field runs the query.   This is very akin to http://processwire.com/talk/topic/1489-how-to-retrieve-possible-pages-list-in-a-page-field, but reducing code duplication and making it as natural as any other field.  The Page input already allows for the query/snippet to provide possible _selections_ at page creation, but not a way to harness that query's results as a field.   Am I making sense?

I've not started digging in to the fieldtypes, and I see http://processwire.com/talk/topic/4079-input-field-for-dimensions/ may be a good place to start down this path, unless there's a module I missed that already addresses this. 

2:  I've seen some screenshots where creating a new Page from a template has a nice layout to the field entries.  I am aware that you can specify the entry widths during declaration.  However, is this an adjust/reload/repeat process to get some fields grouped together on the same line nicely, or is there a way of handling the field entry layout that I'm not aware of?

If either of these questions seem addled in thought, it's me, not you.

Thanks for any help, input, and advice you may provide!

Share this post

Link to post
Share on other sites

Hi Alevine,

One way to accomplish this would be to use Ryan's Hanna code module. Set up a Hanna code, let's say "output_pages" to accept a selector parameter and output what you need. Create a text field that contains the Hanna code and the parameter like  [[output_pages match=template=basic_page]]. 

Hope that helps,


  • Like 2

Share this post

Link to post
Share on other sites


   Thank you for the suggestion.  I'm having issues installing Hanna code (and I've so posted on the support page), but I'm anxious to see if this is the solution that I hope it is.

Thanks again, and I'll post back with my experience.

-- adam

Share this post

Link to post
Share on other sites

Ok, this looks like it's mostly the solution.  The piece that's missing is declaring default text at the field level

1:  hannah code to run my pages selector

2:  field declaration:  Type: Text;  TextFormatter: Hannah; Visibility: Always hidden

        -- default value??

The idea is to add this to a template so the same query is present on all pages/templates using this field.  This keeps the content creators from having to worry about adding it (or even breaking it), and I know it's there and what to expect from it.

I know it'd be easy enough to create a function somewhere to accept a page and return my page lists that I need, but what fun is that? :)

I'm looking again trough all the modules to see if I overlooked a way to allow specifying the default value for a field.

Share this post

Link to post
Share on other sites

Okay, I've solved this for now, tho it does add an extra find call.

1:  Hanna only does text replacement - all you get back from a tag is text.

So, my hannah code executes the query and returns the ids in a piped list

$foundPages = $pages->find($pagesQuery);
$idList = "";
foreach($foundPages as $img)
 $idList .= "$img|";
echo $idList;

2:  I declared my field as a Concat field, with the formatting field as:

[[pages_query pagesQuery=template=template-1]]

3: My code now receives the id list, in pipes, when referencing the field, which makes a 2nd call to find all the ids that were returned.

$myIds = $page->query_pages;
$myPages = $pages->find("id=$myIds");
foreach($myPages as $targetPage)

I don't like having to make a second call to the db, as that's unecessary overhead.  I may try to dive into hanna code code (heh) and see what it would take to return the original results, rather than doing text substitution.   Ryan, any insight would be appreciated here :)

Thanks again, Brent, for directing me to Hanna.  It got me to 99% of where I want to be.

EDIT:  sleep always clears the head.  seralize/unserialize to prevent a 2nd db trip :)  I marked your answer as solved, thank you.  I'll revisit the new Page form layout question at another time.

-- adam

  • Like 1

Share this post

Link to post
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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By snck
      Hi there,
      I have a problem constructing a selector that finds all pages that refer to pages with a specific template.
      I have pages using an event template and I want to show events based on a specific context. In this example I want to filter the results and only show event pages that relate to a specific template (exhibitions) in their page field related_pages.
      What I tried:
      $events = $pages->find("template=event, related_pages.template.name=exhibition"); Unfortunately it does not work (0 results).
      Same with this:
      $events = $pages->find("template=event, related_pages=[template.name=exhibition]"); At the moment I am helping myself with the following lines, but I have a strong feeling that there is a more efficient solution:
      $events = $pages->find("template=event"); foreach($events as $event){ if(!count($event->related_pages->find("template=exhibition"))){ $events->remove($event); } }  
      I really hope that one of you can help me out.
      Thanks in advance!
    • By Kiwi Chris
      The selector in the following code included in a template is returning nothing, however if I take out the compId.resultsdate<={$today} bit, it works fine, although obviously not filtered on the date field.
      $today = strtotime(date('Y-m-d')); $setImages = $pages->find("template=competitionImage, compId={$page->id}, compId.resultsdate<={$today}, compSubject.name=s, imageRating.title=Merit|Honours,check_access=0"); Here's the results of an example from Tracey Debugger
      templates_id=79, resultsdate<=1587729600, status<2048   SELECT pages.id,pages.parent_id,pages.templates_id FROM `pages` JOIN field_resultsdate AS field_resultsdate ON field_resultsdate.pages_id=pages.id AND (((field_resultsdate.data<='2020-04-25 00:00:00' ) )) WHERE (pages.templates_id=79) AND (pages.status<2048) GROUP BY pages.id Over in my ready.php I have inside a hook that refers directly to the page template that's used for the pages in the page field above:
      $today = strtotime(date('Y-m-d')) $event->return = $event->pages->find("template=competition,eventEnd>={$today},eventStart<={$today}"); In this case the filtering on date fields (albeit different ones) works fine. Can anyone suggest why the filter on the date subfield of the page field isn't working?
      Just to confirm, I do have a date value in the field, and it is a date before today. 🙂
      The problem may be something blatantly obvious, but I can't for the life of me figure out why the selector is returning no results when I include the date filter.
    • By Roberts R
      I have simple page structure:
      category subcategory simple-product simple-product simple-product simple-product subcategory .... category2 so Im at category page and running
      $pages->find("template=simple-product, has_parent=$page, limit=8"); and it returns 0 pages
      but this returns 4 pages
      $pages->find("template=simple-product, has_parent=$page"); Can someone explain why limit does not work here?
      So I did some tests and it seems that any limit=n where n is >= actual page count that is possible ... selector return 0 results.
    • By jds43
      Hello, I have a Page Reference by template radio button field to promote a certain page (only two options), but I'd like to target the page that isn't selected. This would be used dynamically throughout the site.
      Does anyone know how I could accomplish this? Would I use something like remove() or not()?
    • By Hubris
      Hi there!
      I'm using some page reference fields to create lists of tags, categories, years, etc.. I'm able to find the pages like so:
      $pages->find("template=project, {$filter}={$page->title}"); Which dynamically does something like: 
      $pages->find("template=project, tags=Experimental"); Only if the value (the page name, like "Experimental") starts with letters. If it starts with numbers, find returns nothing.
      Why is this and how can I fix it?
  • Create New...