Forum
pageDepth value in php
Is there a way of getting the pageDepth value out of the database with php so that I can set it as a variable and pass it into a perch_content_custom template?
Is there a way of getting the pageDepth value out of the database with php so that I can set it as a variable and pass it into a perch_content_custom template?
Basically, I've got a page with multiple item content regions and each item is being output to the page. I'm using this to display an on-page sub nav (using fragment identifiers on each item):
and the template is:
My problem is that I don't want that last
<li>
to display on the 'half day courses' sub page. If I was using perch_pages_navigation I could wrap that last<li>
in<perch:if id="pageDepth" match="eq" value="1" />content<perch:else /></perch:if>
. So I need to find the value of pageDepth on the page in php, set a variable and pass that into the template and use it as the conditional.I haven't tested this, but...
I think you could use
perch_pages_navigation
with thefrom_path
option set to*
(to start outputting at the current page) and also setlevels
to 1 - so you're only outputting the detail for the current page.Pass in a custom template that only outputs
pageDepth
, set the last parameter totrue
and pass that value into yourperch_content_custom
function - usingPerchSystem::set_var
Hi Duncan,
Thanks for the pointer – I'm trying this:
but it echoes out the value of the sub page on both the top level page and its sub page. I tried swapping the value for
pageNavText
and it echoes the name of the sub page on both pages too.Is my code along the lines of what you were thinking?
Hi Martin,
yes, that's what I was thinking. That'll teach me not to try it first...
Hang on, try this:
Use
levels
notfrom-level
Got it! That code outputs the subpage on the top level page, but nothing on the subpage. So I did this on the page:
And a
<perch:if exists="subpage">
in the template.Thanks for your help Duncan :D