Jump to content

Url segments and child url


verdeandrea
 Share

Recommended Posts

Hello,

i read that "URL segments only apply if the requested URL did not resolve to an actual page." (from here)

Is there a way to change this behaviour? 

I have a parent page loading his children via ajax, and i know which children to load from url segments. So that would be nice to have url segments to have precedence instead of children's url.

Thanks!

Link to comment
Share on other sites

so why don't you just load your children via their regular url? seems that there is no need for url segments here ;)

or you modify your url segment and add some kind of prefix that you strip off when requesting the child.

  • Like 1
Link to comment
Share on other sites

Thanks Bernhard,

this is my case:

I have a page "Lawyers" that contains other pages, that are groups of lawyers i.e. "Partners", "Associates", etc. Iniside every group i have pages for every lawyer.
So in the end is something like this:


Lawyers
|__Partners
      |__Donald Duck
      |__Uncle Scrooge
      |__Mickey Mouse
|__Associates
      |__Bugs Bunny
      |__Duffy Duck
      |__Speedy Gonzales

and so on with other groups.

I'm using the lawyers page to load and filter all the lawyers by group, name and others criterias, so i'm loading the filtered data via ajax and using vue.js to show them on the page. I'm also updating the page url, using js, according to filtered data.

For example, my starting url is "/lawyers/". If i filter al the partners that should be "/lawyers/partners/". If i continue filtering for country that should be "/lawyers/partners/italy/". An that is not a problem as long as i start my navigation starting from "/lawyers/".

But, of course, if i go directly to "/lawyers/partners/" pw open the partners page (that does not have a php template). That is why i need everything after "/lawyers/" to be considered as an url segment.

Is there a good way to make it work?

The only other solution i could come up with is using a different page (not "Lawyers") as starting page for searching and filtering lawyers so that i can use url segments without conflicts with children pages. Is there a better solution?

Thanks

Link to comment
Share on other sites

15 hours ago, bernhard said:

Or you modify your url segment and add some kind of prefix that you strip off when requesting the child.

;)

Or you modify your pagenames (eg john-doe-url) then you can use the URL segment and append the "-url" to your filter.

In general it is often a good idea to have all persons under one parent and do the grouping via pagefields (or select options). But maybe it's better like you did in your case. This was just my experience :)

  • Like 2
Link to comment
Share on other sites

  • 4 years later...
On 7/20/2017 at 3:50 AM, bernhard said:

In general it is often a good idea to have all persons under one parent and do the grouping via pagefields (or select options). But maybe it's better like you did in your case. This was just my experience :)

Hey @bernhard, sorry to revive a thread of 5 years ago, but i'm working on a site with a lot of different type of data, and I'm having a hard time deciding how to organize the tree for easy administratation.

But how to keep a visual hierarchy of pages inside the tree?

For example:

|__Lodging
      |__Hotels
            |__ Hotel 1
            |__ Hotel 2
            |__ Hotel 3
      |__Hostels
            |__ Hostel 1
            |__ Hostel 2
            |__ Hostel 3
      |__Cabins
            |__ Cabin 1
            |__ Cabin 2
            |__ Cabin 3

vs

|__Lodging
      |__ Hotel 1
      |__ Hotel 2
      |__ Hotel 3
      |__ Hostel 1
      |__ Hostel 2
      |__ Hostel 3
      |__ Cabin 1
      |__ Cabin 2
      |__ Cabin 3

Wouldn't it be a bit tricky to have hundreds of items in the same page tree? What if you need to add 3 hotels, then 1 cabin, then 2 hostels? everything starts to mix. And how do you identify which are hotels and which are hostels.

And how to avoid ending up with dozens of templates for each subcategory?

I would like to know your experience with such a case.

Thank you

Edited by Krlos
Typos
Link to comment
Share on other sites

Hi @Krlos

that's not an easy question and depends a lot on the use case.

7 hours ago, Krlos said:

I'm having a hard time deciding how to organize the tree for easy administratation.

What are the circumstances that make the decision hard? I can't give any advice without any knowledge about the situation...

7 hours ago, Krlos said:

Wouldn't it be a bit tricky to have hundreds of items in the same page tree?

Tricky? For whom? For the developer? For the person managing content? Counter question: Wouldn't it be tricky to reorganize hundreds of pages once a single thing in your project setup changes? See https://github.com/processwire/processwire-issues/issues/1459 for a recent issue...

8 hours ago, Krlos said:

And how do you identify which are hotels and which are hostels.

Unlimited possibilities using a hook ?

I'm often using http://tabulator.info/ for displaying data and I have a module for that, so for me this is no issue. But you can also use ListerPro or the regular page finder I guess. If you don't have those tools it might be easier to stick with the page tree...

But having business logic in the page tree is - in my experience - not a good idea for projects that need to scale in some extent, might change in the future or have have custom logic and calculations (for example I've built a survey tool where answers have been pages and the parent defined where the answers belonged to. That sounded great and easy on first glance, but the longer the project went and the more feature/change requests the client came up with, the more i regretted the decision and I think it would have been a lot easier to save all those answers under one parent and add a page field to save a reference to the related survey).

But your setup looks like you want to show the items to website visitors under an existing urls, so probably having them where users can visit them makes sense (site.com/lodging/hotels/hotel-a)

  • Like 2
Link to comment
Share on other sites

  • 2 weeks later...

@Krlos I agree with @bernhard - more detail is required on your constraints to really advise.

However we've built a number of data-driven sites using PW in this way and I would say putting all pages of a specific type under one parent is my preferred approach vs nesting in multiple sub-folders. It's also more like a regular database table). You can then just use selectors to filter the output and it makes more sense if you have entities that might apply to multiple parents. E.g. a staff member that works at multiple locations.

For those maintaining the site/data you can make it easy on them by configuring the 'family' tab for each template. So for instance, only a 'hotel' can be added as a child of 'hotels'. When an editor wants to add a new hotel they can't then accidentally use the wrong template, or put it in the wrong place. Finding an existing hotel to edit is as simple as tapping the name into the default PW search box.

  • Like 1
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...