Jump to content

Page Field based on Parent


Tom.
 Share

Recommended Posts

Hello,

Just trying to figure this one out. I have a PageField which pulls Categories. Each Category will have Sub-Categories as it's children. So I have two PageFields on the page, Category and Sub Category. 

I want the Sub-Category PageField to pull back results based on the Category. I thought maybe like Visibility and Required If, I'll be able to use values from fields on that page. So under "Custom selector to find selectable pages" I tried "parent=category" <- Category being the PageField. 

Does anyone know how to do this, or if this is even possible?

EDIT: Figured it out, I used the PHP code instead

Link to comment
Share on other sites

Thanks, I completely forgot to put in the return, now to get it to return rules based on the other PageField. I tried:

return $pages->find("template=subcategory, id=$page->category");

Didn't quite work. I thought I worked it out. 

Link to comment
Share on other sites

Thanks, I completely forgot to put in the return, now to get it to return rules based on the other PageField. I tried:

return $pages->find("template=subcategory, id=$page->category");

Didn't quite work. I thought I worked it out. 

Is the category page field's "Dereference in API as" setting set to Multiple or Single?

  • Like 1
Link to comment
Share on other sites

Is the category page field's "Dereference in API as" setting set to Multiple or Single?

Sorry, you're right. It's a Single, however I've tried:

return $pages->find("template=subcategory, id={$page->category->id}");

Still nothing though strangely. :(

EDIT: 

Haha, never mind I'm being silly. I had a complete brain freeze there. Battling with a cold. Thank you for your help Adrian. 

I needed: 

return $pages->get($page->category)->children();

One question though, is it possible to reload the field via AJAX when the category changes? 

Link to comment
Share on other sites

Haha, never mind I'm being silly. I had a complete brain freeze there.

I was wondering about that actually - how the id of the page could match the category id :)

One question though, is it possible to reload the field via AJAX when the category changes? 

Good question - it is possible, but you need to do things a little differently. Try the following in the custom selector option - not the custom PHP option:

parent=page.category
  • Like 3
Link to comment
Share on other sites

I was wondering about that actually - how the id of the page could match the category id :)

Good question - it is possible, but you need to do things a little differently. Try the following in the custom selector option - not the custom PHP option:

parent=page.category

Perfect, thank you very much :)

  • Like 2
Link to comment
Share on other sites

Quick question on this -

How do I make this visible only if it has results? It's set as a single page. I've tried a few things such as subcategory!='', subcategory!=0, subcategory.count>0 etc.

I guess this isn't possible as the checks are based on the value of the field. Not the amount of pages returned. Based on that I tried category.children.count>0 however that always displayed the field.

However I don't think this is possible either as I believe this only works on count at the moment?

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