Jump to content

Page Depth


Pierre-Luc
 Share

Recommended Posts

I’m currently working on a module called Page Depth that lets you return a page’s depth relative to the root, to a closest selector or a page. Basic functionality is in there. 

It currently has three functions $page->depth(), $page->depthFromClosest() and $page->depthFromPage(). I’m thinking of adding an integer hidden field named depth to prevent having to run the whole functions each time it’s called, but since it’s pretty basic it doesn’t have much impact on the load time even in its current state.

It supports the PageLanguageName module, admittedly I haven’t tried it without it but think it should be working fine. If it doesn’t let me know and I’ll fix it..  finally got a chance to test it, working fine!

I’m publishing it now in its unfinished state thinking some of you might have requests or ideas what this could be useful for. I’m currently using it to prevent too many subpages (where pages are individual comments and would be replies to other comments) on a comment system.

Documentation and download at : https://github.com/plauclair/PageDepth

  • Like 2
Link to comment
Share on other sites

Did you know you can probably do $page->parents->count() to get the depth from the homepage?

The other scenarios are a bit trickier of course.

I think that you probably don't need to have a hidden fieldwork storing this unless you were having dozens of comments deep in your scenario. Even then it's reasonably cheap resource wise.

I would instead make savings by caching the comment output using MarkupCache whenever a new comment is made - that way people just viewing the comments don't incur any overhead, plus you can cache whether or not a reply button exists at a certain depth for your threaded comments.

  • Like 4
Link to comment
Share on other sites

Hey Pete, yes count() works pretty good and it’s really easy to do, but depth() is more of a handy after affect for convenience in the other functions. I think I was adding this way too late into the night and overthinking it a lot, that solution is so much better I’ve switched to it in the last commit..

The field I’m thinking of adding is really more to enable a basic selector for this, but if/when I figure out how to add custom selector function, I might not go that way.

Caching the comment system is a whole other topic, getting page depths is really not what concerns me the most at this point. MarkupCache already does wonders though! ;)

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