bwakad Posted April 13, 2014 Share Posted April 13, 2014 For the life of me, I have now made all templates URL segment enabled. Restarted Xampp. Cleared my brower. Logged out and in again. But on whatever page I go URL segment is simply NOT working! How can you check if $input->urlSegment1 suppose to be working or not? $selects = $pages->find("template=child-template, provincie={$input->urlSegment1}"); // this don't work $selects = $pages->find("template=child-template, provincie={$page->title}"); // this works, but I do not think it's good this way. Link to comment Share on other sites More sharing options...
Soma Posted April 13, 2014 Share Posted April 13, 2014 Url Segments only work for segments that are not already a page. Link to comment Share on other sites More sharing options...
Pete Posted April 13, 2014 Share Posted April 13, 2014 Exactly what Soma said. What you are trying to do above when you say $page->title works sounds like you're trying to find all pages with the template "child-template" that have the current page in the "provincie" field, so you don't need to do anything more complicated than this (because $page is the current page): $selects = $pages->find("template=child-template, provincie=$page->id"); Or if you don't specify a field on the end of $page then it returns the page ID anyway: $selects = $pages->find("template=child-template, provincie=$page"); It sounds like you're trying to find other pages that relate to the page currently being viewed, so you should always try matching the current page's ID, assuming "provincie" is a Page fieldtype? For that fieldtype pages are stored using their IDs. UrlSegments is just over-complicating things at this stage 1 Link to comment Share on other sites More sharing options...
bwakad Posted April 13, 2014 Author Share Posted April 13, 2014 Oooohwww..... That looks so simple! I can't believe I was going for that difficult thing. Stupid stupid stupid. And thank you so much! But this only leaves me with when are we using url segments then? I did not get it when he said 'for pages that don't excist'? I mean, how would you get the url segment if it in the first place did not excist? Link to comment Share on other sites More sharing options...
Martijn Geerts Posted April 13, 2014 Share Posted April 13, 2014 you get them on the page that do exists. domain.com/im-the-curent-page/tralala/ so if im-the-curent-page is the current page, you have the variable from the URL Segment with the value of tralala on $page if ($input->urlSegment1 == 'tralala' ) { echo "Oei !" } or if ($input->urlSegment1 == 'tralala' ) { $just_a_page = $pages->get("name=tralala, parent=1234"); if($just_a_page->id) { $just_a_page->render(); } } Link to comment Share on other sites More sharing options...
bwakad Posted April 13, 2014 Author Share Posted April 13, 2014 @martijn - I tried it on the current page, I don't see on what other page I would get the last piece (drenthe) in the url. root = home page - provincie(page current) / select template - - drenthe (page child) / provincie template ---------------------------------------------------- On current this code : if ($input->urlSegment1 == 'drenthe' ) { echo "Oei !"; } did not display anything. Link to comment Share on other sites More sharing options...
Martijn Geerts Posted April 13, 2014 Share Posted April 13, 2014 Did you read Soma's post ? If www.domain.com/provincie/drenthe/ does exists, $input->urlSegment1 is never triggered. $input->urlSegment1 is the part that should not exist. if you've enabled url segments for the select template type in www.domain.com/provincie/tralala/ (the tralala page should NOT exists) Link to comment Share on other sites More sharing options...
bwakad Posted April 13, 2014 Author Share Posted April 13, 2014 Exactly what Soma said. What you are trying to do above when you say $page->title works sounds like you're trying to find all pages with the template "child-template" that have the current page in the "provincie" field, so you don't need to do anything more complicated than this (because $page is the current page): $selects = $pages->find("template=child-template, provincie=$page->id"); Or if you don't specify a field on the end of $page then it returns the page ID anyway: $selects = $pages->find("template=child-template, provincie=$page"); It sounds like you're trying to find other pages that relate to the page currently being viewed, so you should always try matching the current page's ID, assuming "provincie" is a Page fieldtype? For that fieldtype pages are stored using their IDs. UrlSegments is just over-complicating things at this stage I get my list according to the 'provincie/drenthe'. showing childs with the field 'drenthe'. But the link to the item title for each child is pointing to this page back. <a href="<?php $child->url;?>"><?php echo $child->title;?> Do I have to change this to root or something? Did you read Soma's post ? If www.domain.com/provincie/drenthe/ does exists, $input->urlSegment1 is never triggered. $input->urlSegment1 is the part that should not exist. if you've enabled url segments for the select template type in www.domain.com/provincie/tralala/ (the tralala page should NOT exists) Yes, I did. It's funny you call it tralala. But what exactly should tralala represent? If not a page? Perhaps a user text input or something? How would you get this in the url? Link to comment Share on other sites More sharing options...
Martijn Geerts Posted April 13, 2014 Share Posted April 13, 2014 I get my list according to the 'provincie/drenthe'. showing childs with the field 'drenthe'. i'm confused here. what values should the field drenthe has ? Does it contain a pagearray of all cities in Drenthe ? But in your drawing you draw pages. It's all to cryptic. urlSegments are just a nice fancy alternative to get variables, so you should treat them like that. For relative simple sites you don't need them most of the time. As said before, the best thing you can do is to start simple, and start with the documentation from ProcesssWire. Link to comment Share on other sites More sharing options...
Soma Posted April 13, 2014 Share Posted April 13, 2014 Maybe read the docu again https://processwire.com/api/variables/input/ Youre really a hard nut Link to comment Share on other sites More sharing options...
bwakad Posted April 13, 2014 Author Share Posted April 13, 2014 haha! thanks, I have been told before. I'm so much into details I often stay focused to long on one subject. But I start to see it. Keep patience! Host/provincie/drenthe/something/ (the something page does NOT exists) - it displays 'oei!'So basically this means prevent from entering some kinda fake url, or perhaps redirecting is trying to search with browserbar or maybe give some extra url's. I am thinking SEO advantage... Anyway, I now have to resolve my issue with the $child->url, which is suddenly changed to host/provincie/drenthe - where as it should read: host/parent/itemtitle My bad, had to use echo. Anyway, thanks to soma (looks so angry on the avatar ), pete, adrian, and martijn I can continue. I am really happy you all are so patient. @martijn - it's difficult to me how to present what I have in the system (page tree / templates) to make readers understand it - so if there is a preferred way that people use, I will be happy to do that in future. No problem . Just tell me how most of you want it. Or perhaps make a topic in PUB/DEV TALK for it? And thanks again, you always do your best to explain to a 'hard nut' lol. Link to comment Share on other sites More sharing options...
Martijn Geerts Posted April 13, 2014 Share Posted April 13, 2014 How would you get this in the url? echo "<a href='{$page->url}tralala/'>tralala/</a>"; tralala could be any string you want. 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