I have a Page where has children Pages and all of them are visible. So I wanted to include a Prev/Next Navigation where I have done some other times. But this time, also when I dump() the Page Object, there is no PrevVisible or nextVisible. But I’m 100% sure that they are available. Can this have any other reasons?
It’s hard to say without seeing the code you are trying, but something like this should work, and its pretty much whats in the Kirby documentation. I know the below works, since I just grabbed it from my own site.
@Oli1 Where have you included the navigation? I’m a bit irritated by your dumping of the page object… because it tells you if a page has siblings but not if these are visible or not…
There’s absolutely nothing wrong with your code, but somehow this || statement produces unnecessary long code and duplicate checks. If a page has visible siblings, one of the above conditions is automatically true. Also, I’m not a fan of using @ in front of a variable to suppress errors if the variable is not defined…
that’s true, if I dump() the Page, I get some siblings, but then for what is the hasPrevVisible() function? And normally, if I dump() the Page, it should output a boolean? Here’s the output of the dump().
What’s really strange, I checked the Code in another site and there it’s working?? When does the Page Object tells me if there are prev or next? I included the code directly in the template file. The parent template is “faqs” and the childs does have the template “faq”.
Page Object
(
[title] => Wo sind die rechtlichen Grundlagen für den Explosionsschutz zu finden?
[id] => faqs/wo-sind-die-rechtlichen-grundlagen-fuer-den-explosionsschutz-zu-finden
[uid] => wo-sind-die-rechtlichen-grundlagen-fuer-den-explosionsschutz-zu-finden
[slug] => wo-sind-die-rechtlichen-grundlagen-fuer-den-explosionsschutz-zu-finden
[parent] => faqs
[uri] => /faqs/wo-sind-die-rechtlichen-grundlagen-fuer-den-explosionsschutz-zu-finden
[url] => /faqs/wo-sind-die-rechtlichen-grundlagen-fuer-den-explosionsschutz-zu-finden
[contentUrl] => /content/5-faqs/1-wo-sind-die-rechtlichen-grundlagen-fuer-den-explosionsschutz-zu-finden
[tinyUrl] => /x/3lh5bb
[root] => /xxx/content/5-faqs/1-wo-sind-die-rechtlichen-grundlagen-fuer-den-explosionsschutz-zu-finden
[dirname] => 1-wo-sind-die-rechtlichen-grundlagen-fuer-den-explosionsschutz-zu-finden
[diruri] => 5-faqs/1-wo-sind-die-rechtlichen-grundlagen-fuer-den-explosionsschutz-zu-finden
[depth] => 2
[num] => 1
[hash] => 3lh5bb
[modified] => 2018-10-10T20:30:15+00:00
[template] => faq
[intendedTemplate] => faq
[isVisible] => 1
[isOpen] => 1
[isActive] => 1
[isHomePage] =>
[isErrorPage] =>
[isCachable] => 1
[isWritable] => 1
[content] => Content Object
(
[root] => /xxx/content/5-faqs/1-wo-sind-die-rechtlichen-grundlagen-fuer-den-explosionsschutz-zu-finden/faq.txt
[fields] => Array
(
[tab1] =>
[title] => Wo sind die rechtlichen Grundlagen für den Explosionsschutz zu finden?
[accordion] =>
[tab2] =>
[headline] =>
[cta] =>
[tab3] =>
[metatitle] =>
[metadescription] =>
[text] => Für Hersteller gilt seit 20.4.2016 die EU Richtlinie 2014/34/EU (ATEX 114). Für Benutzer ist dies seit 1.6.2015 in der Gefahrstoffverordnung verankert, die die EG Richtlinie 99/92/EG umsetzt. Die erforderlichen Prüfungen sind in der Betriebssicherheitsverordnung geregelt.
[categories] => filter-explosionsschutz, filter-whg-fachbetrieb
[aufrufe] => 73
)
)
[headers] =>
[children] => Children Object
(
)
[siblings] => Children Object
(
[0] => faqs/wer-ist-fuer-den-sicheren-betrieb-einer-explosionsgefaehrdeten-anlage-verantwortlich
[1] => faqs/ab-wann-spricht-man-von-einer-ueberwachungsbeduerftigen-explosionsgefaehrdeten-anlage
[2] => faqs/was-muss-der-auftraggeber-tun-wenn-er-eine-ueberwachungsbeduerftige-explosionsgefaehrdete-anlage-hat
[3] => faqs/was-muss-geprueft-werden-und-wie-sind-die-pruefintervalle
[4] => faqs/wie-hoch-sind-die-kosten-fuer-eine-pruefung
)
[files] => Files Object
(
)
)
No, if you dump a page object, you get a page object, what you’ve got there is perfect. Could you post your prev/next navigation code? Or is it the same as what @jimbobrjames posted?
The page object doesn’t tell you if there are any visible prev or next pages; it tells you that there are siblings. To check if the page has any visible siblings, you can do the following
dump($page->siblings(false)->visible();
The false parameter tells the function not to include the current page. You can remove the parameter, then you will actually see the current page at it’s position within the collection.
hasPrevVisible()/hasNextVisible()check if the current page has a visible sibling in a position prior to/after itself in the collection, they return a boolean.
What plugins do you have installed? If you don’t get it to work, feel free to send me your project. I‘m on the road today, but could take a look tomorrow.