lenoir Posted October 24, 2012 Share Posted October 24, 2012 Hi there, Simple question needs simple answer… I'm still a newby and trying to get my head round pw. I'm trying to access (and eventually get the path) to a particular page somewhere else in the tree, without knowing the complete path, only knowing the name of the page. I'm getting the name of the page with urlSegment. Code looks like this so far: $myPage=$input->urlSegment1; $pathToPage=$pages->find($myPage)->path; Played around with it, browsed the forum and failed embarassingly. Any suggestions? Thanks. Link to comment Share on other sites More sharing options...
Pete Posted October 24, 2012 Share Posted October 24, 2012 Try something like find("name=$mypage") in your code above since you don't have the full path available to you. I'm assuming you're wanting to match against the sanitised page name (ie. the URL version of the page title) - if not its title= and not name= Link to comment Share on other sites More sharing options...
apeisa Posted October 24, 2012 Share Posted October 24, 2012 One thing to remember: there can be multiple pages with same names (but with different parent). But here is how you do it (this returns the first page it finds): $myPage = $input->urlSegment1; // Remember to sanitize! $myPage = $sanitizer->pageName($myPage); // $pages->get() returns single page while $pages->find() returns PageArray $p = $pages->get("name=$myPage"); // And finally, we want the url echo $p->url; 2 Link to comment Share on other sites More sharing options...
lenoir Posted October 24, 2012 Author Share Posted October 24, 2012 Thanks to both of you! I wasn't aware of the sanitizing process… Works like a charm! I'm using the page name because it appears in the URL and i want to keep them clean. 1 Link to comment Share on other sites More sharing options...
ryan Posted October 24, 2012 Share Posted October 24, 2012 Technically the pageName sanitizer isn't actually necessary here (as PW wouldn't even get the request if the pagename wasn't in the right format), but it is a best practice to sanitize anything you are planning on putting in a selector. So I would do it the same way as apeisa and sanitize with pageName, even if it's not technically required. 2 Link to comment Share on other sites More sharing options...
lenoir Posted October 25, 2012 Author Share Posted October 25, 2012 One thing to remember: there can be multiple pages with same names (but with different parent). …and this problem just occured. I could solve it by adapting the conflicting page's name, but on the long run it's definately not going to be the best bet. Should I avoid using their name to get pages? Link to comment Share on other sites More sharing options...
Soma Posted October 25, 2012 Share Posted October 25, 2012 You could use ID_name or name_ID. 1 Link to comment Share on other sites More sharing options...
lenoir Posted October 26, 2012 Author Share Posted October 26, 2012 Hi, I'm posting another question here, since it's related. I have a URL like this: …/company/team On this page, i have all the team members linked <a href='#/{$child->name}'>{$child->title}</a> However, i can't get the urlsegment to know the name of the team member. $member=$input->urlSegment2; urlsegment1 doesn't work either. Won't UrlSegments work with dashes? Any suggestion? thanks for your help! EDIT: Url Segments are allowed. Link to comment Share on other sites More sharing options...
lenoir Posted October 26, 2012 Author Share Posted October 26, 2012 Ok, solved the issue. Apparently urlSegments don't work with "/#/". I replaced this URL: …/company/team/#/member by: …/company/team/member/member-name This not only works, but actually makes more sense… Link to comment Share on other sites More sharing options...
Pete Posted October 26, 2012 Share Posted October 26, 2012 A hash is usually used in a URL to jump to a HTML anchor further down a page (like <a name="bob"></a> halfway down a page called "tim.html" could be called via yoursite.com/tim.html#bob and that page would load and automatically jump down to that anchor). I'm not sure an anchor would work any other way due to this. Link to comment Share on other sites More sharing options...
lenoir Posted December 17, 2012 Author Share Posted December 17, 2012 Hi there. One month later, one project later: same issue (almost). Processwire's growing on me quickly, but there are a couple of things that kind of drive me nuts. And one of these is the whole selector / urlsegment thing. For some reason I struggle a lot with those and can't find answers to my questions in the tutorial or on the web. Therefore, my issue below. The following code doesn't work. $segment=$input->urlSegment1; $segment=$sanitizer->pageName($segment); foreach($pages->find('wh_mitarbeiter_kategorien=/portrait/mitarbeiter/kategorien/{$segment}') as $child){ //magic here. } Now if i replace the {$segment} bit by 'a-bis-z' (which is the category i'm looking for), it works perfectly. Any idea? Or do you need more information? Thanks for the help. Link to comment Share on other sites More sharing options...
Soma Posted December 17, 2012 Share Posted December 17, 2012 $pages->find('wh_mitarbeiter_kategorien=/portrait/mitarbeiter/kategorien/{$segment}') 'strings' won't get parsed in php try "strings" Link to comment Share on other sites More sharing options...
lenoir Posted December 17, 2012 Author Share Posted December 17, 2012 hmm. Tried it, doesn't solve the problem though. hmm N°2. Might have actually solved the problem. I had to reset Safari and now it works… Go figure. Thanks Soma. 1 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