Jump to content

url with urlSegment


mel47
 Share

Recommended Posts

Hi,

I'm quite sure to have read everything, doc and forums, about urlSegment, but I'm still not understanding how to use it. After have set my categories with this excellent post, I'm unable to fix url as I want.

Page title             |         Template             | actual url                                   |    url I want

Categ-publi         |         parent_categ      |  categ-publi/article                     | publication/article
   -- Article           |         categories           |

Publication          |        basic-template    | publication/example1               | publication/article/example1
   -- example1      |        publication          |

 

For which template I should activated urlSegment and in which template file I should add some code, probably something like this (which didn't work obviously)?

if($input->urlSegment1 == 'publication') {
 echo $pages->get('/publication/$categ/')->render();
 return;

} else if($input->urlSegment1) {
 // throw a 404
 throw new Wire404Exception();
}

Thanks so much.

Melanie

 

Link to comment
Share on other sites

I have to leave in a minute, but I just took a look at your site (using the login details you gave me the other day). I am not sure what the contents of a valid urlsegment would look like, but can I suggest using the template editor from Tracy (I set it up for you) to make a bd($input->urlSegment1); as well as maybe a bd('test'); inside some of your conditionals to check that they are being processed as you expect. There is a lot of logic in your publications template and it's not easy to figure out what is doing what. A little debugging should help you to figure out what is what :)

  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...

Hi @adrian,

I don't know if I should post here but there something strange happening with Tracy 3.3.1 (in my local installation of PW3.0.33). Before this version, whatever to which page I try bd($input->urlSegment1), I always get " " as answer. But now I get "bookmarks" as result. But my url is now ".../en/publication/example1/bookmarks/", a really unusual and incomprehensible one. Now I have tons of pages like this ".../en/team/bookmarks/bookmarks/bookmarks/bookmarks/bookmarks/bookmarks/bookmarks/bookmarks/bookmarks/bookmarks/bookmarks/bookmarks/bookmarks/bookmarks/bookmarks/bookmarks/bookmarks/bookmarks/bookmarks/bookmarks/", with 404 error.

When I disable Tracy, url come back to normal.

But at least, now I understand a little bit the concept of urlSegment which I misunderstood... It's something we added to the regular url? In that case, it's normal I didn't get a dump answer. But I still don't understand how to change "en/categ-publi/article" to "en/publication/article" if each part of the url is not a urlsegment...

I'm lost, I think... :(

Thanks

Edit: OMG, just realize I completely and totally understood urlsegment concept...

 

Link to comment
Share on other sites

@mel47 - I am definitely curious about the interaction you seem to be getting with Tracy and url segments, Based on your edit it sounds like you finally understand how url segments work, which is great, but we do need to figure out all those /bookmarks/ you are getting. I have seen a single /bookmark/ before but it wasn't related to Tracy. Any chance I could take a look at the server that is doing this, with instructions on what page to be on and how/where you are making that bd() call?

It's late here, so I won't be getting back to you till morning.

 

Link to comment
Share on other sites

@mel47 Maybe you'll want to find the requested page with this code

echo $pages->get("/publication/$categ/")->render();

Did you spot the double quote surrounding the the selector? In PHP this is called string interpolation. At runtime the $categ variable will be replace by its actual value in the selector. More about this here : PHP The Right Way. (See the Double quotes section).

 

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...