suntrop Posted April 13, 2014 Share Posted April 13, 2014 I've got some kind of blog setup with different topics and each should use its own set of categories/tags. Home BlogTopic ACategories Tags Articles Topic BCategories Tags Articles Topic CCategories Tags Articles How do I have to write my custom selector for categories/tags to choose just from the items within the current topic? I can't use one of the defaults (parent page or specific template). I need to select the 2nd parent and find the category or tag template. But couldn't figure out, how to go up two times. Link to comment Share on other sites More sharing options...
teppo Posted April 13, 2014 Share Posted April 13, 2014 Take a look at the example below "Custom PHP code to find selectable pages": Example: return $page->parent->parent->children("name=locations")->first()->children(); Isn't that almost exactly what you need here? Of course you'd have to use ...->child("template=categories|tags")->children() or something like that. Link to comment Share on other sites More sharing options...
suntrop Posted April 14, 2014 Author Share Posted April 14, 2014 It is! Thanks for your help Teppo. I hoped there is a way without PHP code, because it doesn't work with PageAutocomplete. However, it works and there aren't a lot of tags in there. Link to comment Share on other sites More sharing options...
suntrop Posted April 14, 2014 Author Share Posted April 14, 2014 Well, I think I was to happy and didn't tested it completely. I noticed I can still select all tags, not only these saved underneath the parent parent. I thought I have to deselect the "Parent of selectable pages" and after I did that, I get this error on all pages I want to edit: Recoverable Fatal Error: Argument 1 passed to InputfieldPage::___findPagesCode() must be an instance of Page, none given (line 168 of /serverpath/wire/modules/Inputfield/InputfieldPage/InputfieldPage.module) I could go back and select the Homepage as parent, but after saving I still get the error message. Looks like I damaged something Link to comment Share on other sites More sharing options...
kongondo Posted April 14, 2014 Share Posted April 14, 2014 I think that error means the selector did not find a page to return. This could be because it is hidden or unpublished or the selector is just wrong . I have re-read your post and not getting you clearly. Could you explain what you want to do using the pages in your tree (above) as examples? E.g. "I want to select the children of Topic A when I am editing the page Topic A"...i.e. be as specific as possible. Link to comment Share on other sites More sharing options...
suntrop Posted April 14, 2014 Author Share Posted April 14, 2014 (edited) I deleted the selector via PhpMyAdmin and now I have access to my pages again. Could you explain what you want to do using the pages in your tree (above) as examples? Let's say I am editing the article … … /blog/topic-a/articles/entry/. On that page I only want to see tags saved in /blog/topic-a/tags/ … /blog/topic-b/articles/entry2/. On that page I only want to see tags saved in /blog/topic-b/tags/ I've attached a screenshot, that shows which tags are selectable and which tags are not. EDIT: I have to use the tags field on the user template as well. It would be great if I can select and add from all tags for a user. Edited April 14, 2014 by suntrop Link to comment Share on other sites More sharing options...
suntrop Posted April 14, 2014 Author Share Posted April 14, 2014 Seems I've found my selectors if ($page->template == 'admin') { // Find all tags, when editing users return $pages->find("template=tag"); } else { // Find tags only from current topic return $page->parent->parent->find("template=tag"); } Link to comment Share on other sites More sharing options...
kongondo Posted April 14, 2014 Share Posted April 14, 2014 (edited) In that case, Teppo's code should work. It works for me as follows.. return $page->parent->parent->child('name=tags')->children(''); ..and in that page field, under "Input" -> template of selectable page(s) I have selected 'tag' (the template of all tags (A, B, C, D). This last bit is unnecessary; the selector still works but I'd keep it just to optimize the find... Edit I posted a second after or two after you did....Yep. that works too..but my selector won't bother with looking inside 'categories' or 'articles'; It will go straight for 'tags'....I think ....not a big deal probably Edited April 14, 2014 by kongondo Link to comment Share on other sites More sharing options...
suntrop Posted April 14, 2014 Author Share Posted April 14, 2014 Thanks kongondo. I almost got your update the time I saved my post I changed the selectable template as well, didn't know it makes search faster. Link to comment Share on other sites More sharing options...
kongondo Posted April 14, 2014 Share Posted April 14, 2014 I am guessing a fraction faster (I could be wrong) just because it is more specific....but in a real world scenario, especially in the backend, maybe it is not a big deal...But, doing it that way also reminds you what exactly you were looking for or in case there are multiple admins on the site, just to make it easier to know what's going on... Link to comment Share on other sites More sharing options...
kongondo Posted April 14, 2014 Share Posted April 14, 2014 Oh, you can mark your answer as 'best answer' aka topic solved Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now