swissdoode Posted October 10, 2016 Share Posted October 10, 2016 Hi y'all I just read a tutorial about how to organize data in PW and raised an eyebrow on one particular topic. In the tutorial, a website for cars is built, with one of the attributes being the build-year of the car. It is suggested to use the pageField and create a top page with the attribute-title and sub-pages with the contents to choose from. So far so good and I can follow that. But for the building-year, this sounds weird. Assuming my year range goes from 1916 - 2016, I'd have to create 100 pages. Ain't that a little too much? I can see the advantages of this approach (selecting from the field, for example as discussed elsewhere in this forum) but just to create those 100 pages would take quite a while and even worse, for every new year I'd have to create another page. Is this really the best approach or do you guys have other suggestions? Link to comment Share on other sites More sharing options...
teppo Posted October 10, 2016 Share Posted October 10, 2016 I haven't followed said tutorial myself, but I probably wouldn't store years as pages. What I would rather use for storing a year (and nothing more) would be an integer field, or if it really has to be a dropdown on the page editor, I might use an Options field instead. Just my five cents 3 Link to comment Share on other sites More sharing options...
adrian Posted October 10, 2016 Share Posted October 10, 2016 It really does depends on your needs. @teppo has a valid point about using the Options field, but I have actually used pages for storing years because of all the other possibilities of using a page field provides (too many to go into here). Not saying I wouldn't use the Options field for years in a different project, but just saying you should read up and plan ahead before deciding. Remember that pages are just database rows, so 100 rows is not a big deal. Also, if you are worried about creating those pages, check out: or 3 Link to comment Share on other sites More sharing options...
teppo Posted October 10, 2016 Share Posted October 10, 2016 @adrian: to be fair I was about to mention Batch Child Editor, but in the end couldn't think of any solid benefits for pages vs. integers. Now that I think about it, I guess you could do something like use a specific template for your year pages and have them render all related items right there.. which is pretty neat. You could do the same thing with URL segments without having those pages there (this is what I've done in at least one project), but a page-based approach would, at the very least, be more obvious. So yeah, there are some valid reasons to use pages That being said, I do have to point out that each page is actually a bit more than just a row in the database, and while ProcessWire can handle tremendous amounts of pages without breaking a sweat, often they are not the most efficient solution. 1 Link to comment Share on other sites More sharing options...
adrian Posted October 10, 2016 Share Posted October 10, 2016 I definitely try to use the Options fieldtype when I can - I just try to think through fully what flexibility I might be giving up. Unless I am missing something, I don't think there is a way for site editors to add new items to an Options field, so wouldn't that be one of the biggest difference right there? One of the other key reasons I used Pages for years in that one project was because I wanted the year pages to drive the rows in @kongondo's excellent Matrix fieldtype. Although since he introduced the custom php code option, it might actually be possible to do that with an Options fieldtype now Link to comment Share on other sites More sharing options...
teppo Posted October 11, 2016 Share Posted October 11, 2016 11 hours ago, adrian said: Unless I am missing something, I don't think there is a way for site editors to add new items to an Options field, so wouldn't that be one of the biggest difference right there? Agreed. With Options field I'd suggest adding extra 10 years or so right from the start.. and if the site is still running after a decade, you can step in and add +10 years, etc. 1 Link to comment Share on other sites More sharing options...
kixe Posted October 11, 2016 Share Posted October 11, 2016 13 hours ago, swissdoode said: t is suggested to use the pageField and create a top page with the attribute-title and sub-pages with the contents to choose from. So far so good and I can follow that. Keeping an eye on flexible filtering and output options I would store all the cars under the same parent and control the output via urlSegments. In this case an integer field is good and enough. Output path to list all cars /cars/ Output path to list cars builded in 1976, whereas urlSegment1 = filter-key and urlSegment2 = filter-value /cars/build/1976/ Read more about urlSegmentshttps://processwire.com/api/variables/input/ 2 Link to comment Share on other sites More sharing options...
swissdoode Posted October 11, 2016 Author Share Posted October 11, 2016 Thanks guys I still find it odd, but I can see the advantages. And thanks for pointing out the Page Field Select Creator. 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