Theme twig code to include page from the /pages area?

I don’t know why I can’t get my head around how to do this, it seems like it would be simple enough. In a theme template I’m writing, I want to {% include %} a file not from the theme area but from the /pages area. Might someone help me out?

Damn I should have put this in the theme section, sorry. If it can be moved, please do.

What are you trying to do, exactly? Including a .md file?

If you want to ‘find’ a page and include it, you can simply do this

In my theme, I need to pull in a specific sub page to the current page if it exists. It didn’t occur to me to use a for loop because the sub page was always going to have the same name and I was looking for only one specific page, so I was getting way hung up on the pathing using %include% in the template.

Basically it’s going to be a file that will serve as a sub menu relevant only to the page you’re looking at. I wanted to do this from the template, not from the current page’s .md file.

/pages
…01.page1/
…02.page2/
… …menu/
… …other-sub page1/
… …other-sub page2/
…03.page3

When the template for 02.page2 loads the content, it would see the menu/ sub page and load the .md inside it.

I think the for loop would work great, just check the value of p for “menu” and then include it if it matches?

I would create a twig file in my theme that basically found the pages in question and looped over them to create the sub menu.

Then i would include this sub menu twig template file from the template file that ‘only’ my pages that should have the sub menu used.

This is really a common sort of thing. There is a similar approach in the blog skeleton with anitmatter that only loads a sidebar for pages in the blog, so that’s the blog and item templates.

Yeah I was looking for a code example in exactly that place, I think my mind was approaching it differently and I wasn’t looking for the method you describe, thank you, big help!

@rhukster, I’ve used that trick for my website. When I looked at the code I noticed the find method is deprecated: is there a mistake or I should look to another method?

Page.find() is not deprecated. Where are you seeing that?

Sorry, I forgot to post the link to Github that point that. Here it is https://github.com/getgrav/grav/blob/develop/system/src/Grav/Common/Page/Page.php#L1782

That’s most probably a forgotten line. Feel free to use that, I’ll remove @deprecated from the method signature.