Jump to content

Advanced Page Field Labels


Pete
 Share

Recommended Posts

Hi folks

So I actually just added this as a pull request on Github before figuring out it's already possible in the system.

What I wanted was an ASMSelect field (can be a normal select or other Page field) where the list was ordered in a certain way and pulled from two sets of pages with different templates.

The trick was that I wanted the labels for one set of pages to include the parent page name in the label so they're sorted by parent title, then title, but the other set of pages was just to be added to the end in alphabetical order.

I've anonymised the example somewhat, but I have a medical blog where I wanted to categorise posts against medical procedures listed on the site, as well as other blog-specific, general categories.

To achieve what I wanted, I selected ASMSelect as the Page Inputfield type, then used the "Custom PHP code to find selectable pages" option and did this:

$options = new PageArray();
foreach ($pages->find("template=surgery, sort=parent.name, sort=name") as $category) {
    $category->title = $category->parent->title . ' / ' . $category->title;
    $options->add($category);
}
$options->add($pages->find("template=blog-category, sort=name"));
return $options;

This results in a nice, alphabetised list such as:

Surgery Category A / Procedure 1

Surgery Category A / Procedure 2

Surgery Category A / Procedure 3

Surgery Category B / Procedure 4

Surgery Category C / Procedure 5

Surgery Category C / Procedure 6

General Category A

General Category B

General Category C

and so on, so the surgery pages are in the format {parent.title} / {title} in the Select list, and the blog-category pages are just the normal {title}, all ordered alphabetically by parent (where necessary) and page title.

Nice and easy :)

  • Like 13
Link to comment
Share on other sites

Just a quick note - the point of doing this was to categorise blog posts both against existing pages (rather than having blog categories with the same or similar names) as well as additional categories that only apply to blog posts.

This makes for far easier cross-linking of content (I can have the latest blog post for a type of surgery teased on that surgery page), which is something ProcessWire handles beautifully.

Link to comment
Share on other sites

  • 3 weeks later...

Something else to note as per this Github discussion: https://github.com/ryancramerdesign/ProcessWire/issues/1466#issuecomment-150174471

Whilst setting the value of the "title" field to something custom for this purpose shouldn't mean the actual page title gets overwritten, you never know what custom modules are running in the background that might cause your custom title to get saved, however unlikely. If you want to play it really safe, assign the custom value to _title instead of title (so just a fake field name) and then set the option in the field setting to {_title} instead of {title}

It's not paranoia if it saves you from a lot of headache further down the line ;)

  • Like 2
Link to comment
Share on other sites

I was using this since a long time. I also noticed that ListerPro doesn't use that concated title for the first result. Strange.

It was definitely one of those things where when I was having the conversation with Ryan it suddenly clicked that I'd overlooked such a simple option. Still looking for something more complicated when ProcessWire offers so much simplicity and elegance - one day I will learn ;)

Link to comment
Share on other sites

Well you still can't use something like "_title" as a column field in Lister. It's just that only the first result doesn't show the concated title, but all following result would. I haven't been able to look into it or report it. Maybe about time :)

And {_title} in template label is very new that didn't exist back then.

Link to comment
Share on other sites

  • 2 months later...

@LostKobrakai
I am looking for a modification of Fieldtype Concat module, which allows to pull values from parent page fields too (via dot syntax). Is this implemented in the modified module? Would you share your module? :)
 

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