Gazley Posted August 25, 2012 Share Posted August 25, 2012 Hi there, I have an Album page that represents a photo-album of images under a Galleries parent. Quite often, the Album is associated with some other event on the site like, a News or Blog post. I have created and added a Page field to the Album template so that I can associate the Album with its associated post, where one exists. However, the associated post may or may not share the same template. Even if it did, in the Album page, the new Page field just has a drop-down list of titles that will become too large to manage in this way. What I really would like to be able to do is pick the associated post in the Album page via a Page tree. Is there a way to do this? Thanks. Link to comment Share on other sites More sharing options...
Soma Posted August 25, 2012 Share Posted August 25, 2012 You can set the input of Page fieldtype to PageListSelectMultiple to have a page tree to select from. I think doing it the opposite way is much better, have the page select on articles to add albums. 1 Link to comment Share on other sites More sharing options...
Pete Posted August 25, 2012 Share Posted August 25, 2012 Go to edit your field and under the input tab of the field change the "Input field type" from Select to "Page list select". Tada! You can now browse the page tree On the same tab you can also set the page parent to restrict the list of selectable pages. If you have an awful lot of pages and you're the only one maintaining the site, or other people know what's on the site, you could also change the input field type to Autocomplete (can't remember if you have to install that FieldType module first or if it's in by default nowadays). EDIT: I need to type shorter replies so Soma doesn't beat me to it 1 Link to comment Share on other sites More sharing options...
Gazley Posted August 25, 2012 Author Share Posted August 25, 2012 Go Pete - you're the man! Thanks for that tip - it was staring me in the face. I picked asmSelect because that's what I'd used on other Page types not twigging that "Page list select" would let me select pages from a list! doh (clue's in the name) <blush> So awesomely powerful yet simple at the same time. I'm replicating stuff that I hand coded in this site first time round and it originally took ages. With PW, there's just some simple way to do virtually everything I previously custom coded. One thing that I did notice is that originally, I tried to used a custom selector so that I could specify multiple templates that the associated page(s) may be based on. I "discovered" that using "template=template1,template2" causes a PW error, when my intention was to simply AND the templates. It didn't crash using OR '|' but, it only returned data for one of the templates in the OR'd list. Is there a way to express template can equal multiple values? Cheers! Link to comment Share on other sites More sharing options...
Gazley Posted August 25, 2012 Author Share Posted August 25, 2012 Hi Soma, The posting *can* already select an Album that it's associated with. However, when I'm listing out the Albums, I want to include things like the post title and summary to give the Album some context. I realise I could query back to the postings to see if there is one with an Album of the same name. However, I figured (rightly or wrongly) that if I could specify an associated posting (from anywhere on the site) with the Album at design-time, at run-time, there is an exact path back to the associated post, resulting in a quicker search/retrieval. Thanks! Link to comment Share on other sites More sharing options...
Soma Posted August 25, 2012 Share Posted August 25, 2012 If you select an album from pages and article you don't have to specify multiple templates, also if you at the end it's the article you edit, so to change the album you could do it right there and not have to go to the album page to change it. Link to comment Share on other sites More sharing options...
Gazley Posted August 25, 2012 Author Share Posted August 25, 2012 I was referring to selecting multiple templates before I'd learned about PageListSelectMultiple. I understand that I don't need multiple templates now. I was just commenting on the fact that trying to AND template values seems to upset PW. You make a good point about not having to keep two Pages in sync with each other if the posting subsequently chose a different Album. Like I said, I figured that having the exact path of the posting available to the Album would make for speedier retrieval of data from the posting when listing the Albums. In the absence of a specific link from the album back to the post, PW would potentially have to search the whole site looking for pages that had a field that matched the Album - even then, it may not find any because the Album may be a general Album not linked to any post at all. Link to comment Share on other sites More sharing options...
Soma Posted August 25, 2012 Share Posted August 25, 2012 One thing that I did notice is that originally, I tried to used a custom selector so that I could specify multiple templates that the associated page(s) may be based on. I "discovered" that using "template=template1,template2" causes a PW error, when my intention was to simply AND the templates. It didn't crash using OR '|' but, it only returned data for one of the templates in the OR'd list. Is there a way to express template can equal multiple values? "template=tmpl1|tmpl2|tpml3" as the custom selector works just fine. Not sure what is the issue on your side. May the pages are hidden or something. Try adding ",include=hidden". Link to comment Share on other sites More sharing options...
Gazley Posted August 25, 2012 Author Share Posted August 25, 2012 When I tried "template=tmpl1|tmpl2|tpml3", I got entries from only one of the templates, not all of them. There's no issue. The pages aren't hidden - I'm probably not explaining myself very well. Thanks for your help with this. It's working well! Link to comment Share on other sites More sharing options...
Soma Posted August 25, 2012 Share Posted August 25, 2012 I was referring to selecting multiple templates before I'd learned about PageListSelectMultiple. I understand that I don't need multiple templates now. I was just commenting on the fact that trying to AND template values seems to upset PW. AND won't work because you don't have pages with multiple templates that would fit the selector. "|" works just fine here and is the way supposed to do it. You make a good point about not having to keep two Pages in sync with each other if the posting subsequently chose a different Album. Like I said, I figured that having the exact path of the posting available to the Album would make for speedier retrieval of data from the posting when listing the Albums. Don't worry about speed here, even with 100'000 pages you won't notice any speed difference really. In the absence of a specific link from the album back to the post, PW would potentially have to search the whole site looking for pages that had a field that matched the Album - even then, it may not find any because the Album may be a general Album not linked to any post at all. That's dependent on how you write the code, either way you would counter that problem not having associated with a post. When I tried "template=tmpl1|tmpl2|tpml3", I got entries from only one of the templates, not all of them. There's no issue. The pages aren't hidden - I'm probably not explaining myself very well. Thanks for your help with this. It's working well! I'm using this in many places and it works well. Even tested it on my local in latest PW. Link to comment Share on other sites More sharing options...
Gazley Posted August 25, 2012 Author Share Posted August 25, 2012 Soma, I've done it your way, removing the field from Album pointing to the posting in favour of: $posting = wire('pages')->find("album=$album"); Works well and hopefully will be fast enough! Thanks for the suggestion Link to comment Share on other sites More sharing options...
Soma Posted August 25, 2012 Share Posted August 25, 2012 Doing exactly these things is where PW shines, it's designed for this and very very fast. Page relations like this are indexed and the queries are ultra fast. Also it doesn't load all pages with their data in memory, it only does load data on demand. Link to comment Share on other sites More sharing options...
Soma Posted August 25, 2012 Share Posted August 25, 2012 $posting = wire('pages')->find("album=$album"); You could also do $posting = wire('pages')->find("template=templ1|templ2, album=$album"); To further limit the pages that will be searched. Or if suiteable add has_parent selector $posting = wire('pages')->find("has_parent=id1|id2, template=templ1|templ2, album=$album"); 1 Link to comment Share on other sites More sharing options...
Gazley Posted August 25, 2012 Author Share Posted August 25, 2012 Very nice 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