bwakad Posted August 26, 2014 Posted August 26, 2014 I am having trouble with a selector. In a normal way I would know the "country-name" and "province-name". So this would work: foreach ($pages->get('/personal-info/countries/country-name/province-name/')->children as $child) { But I only know the "province-name" for example "Drenthe". parent="/drenthe/" does not work, how do I get to those children? Tree: - home -- personal-info --- countries ---- NL ----- Drenthe ------ child ------ child
marcus Posted August 26, 2014 Posted August 26, 2014 Do the childs of Drenthe have something special worth selecting, a common template, a special field or so?
bwakad Posted August 26, 2014 Author Posted August 26, 2014 Not really because children are nested inside each parent: Tree: - home - personal-info -- countries --- NL >>>>>>>>>>>>>>>>>>>>>>>>> same level parents DE || FR || etc. ---- Drenthe ----- child ----- child First I was thinking of a template for each country, but that would still leave me with a problem: NOT knowing the country name. The only thing I know IS the province name "drenthe".
marcus Posted August 26, 2014 Posted August 26, 2014 I'm currently reading this post by Ryan regarding subselectors. Since I assume you're running a dev version, this may help somehow nesting your query: https://processwire.com/talk/topic/3768-processwire-dev-branch/?p=64049
marcus Posted August 26, 2014 Posted August 26, 2014 But somehow I got the impression this is all too complicated. I guess you are trying to list cities (children of provinces), right? Why not give them city templates and query for these? Other question: from which part of your tree are you searching from, meaning: how close to the desired pages are you when firing this query?
bwakad Posted August 26, 2014 Author Posted August 26, 2014 to answer first question: Maybe I should do it like this... country-template = for country names province-template = for province names city-template = for city names I could probably query for : "template=province, name=drenthe" fetch children. Even though the province-template holds more names from other countries. your second question: I use it to fill a select by the parent/child name - in this case "drenthe". Path from root is: /personal-info/countries/nl/drenthe/. So I am on any level... It's just that I do not know the /nl/ part. It could be fr, de, etc.
Soma Posted August 26, 2014 Posted August 26, 2014 $province = $pages->get("name=provincename"); But usually you have the select option value the ID since name isn't unique.
bwakad Posted August 26, 2014 Author Posted August 26, 2014 Dang! and I just made and assigned the templates. Which also work fine. Anyway, thanks Soma (new title for you > life-saver) I do have a question, because my posts (eventually lead to the same thing) but are scattered so much. I have the topics: "states and cities", "select - then auto values", and this one "trouble with selector". Is it possible to merge them and call it "Cascading / Dynamic Selects front-end". or something similar... The cascading is working between 3 selects, and only need to fine tune some parts...
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