anchorcms/anchor-cms

Include a file from outside the Anchor scope

matronator opened this issue · 2 comments

Maybe a silly question, but I'm having some trouble including a file that is one directory above the Anchor installation directory.

Basically, I have a regular website with just HTML and some basic PHP and then I have a folder /blog where I installed Anchor. On the website I use require_once 'menu.html'; to include the top navigation menu on all pages on the site. This however breaks in the /blog section, because Anchor sets its own document root, so I can't access the menu.html file from the actual website root.

For now, I just copied the menu.html file to the default theme folder in Anchor, so I now have to update both files simultaneously when making changes.

Is there a way to reach out of the Anchor folder to access the menu.html file and how would I do it, please? I'm kinda new to the whole PHP file/folder/server system structure.

Hey @matronator, just update that require to the following: require_once __DIR__ . '/../../menu.html'. Make sure to go as many levels up as your setup requires. The __DIR__ constant always points to the directory of the current PHP script (without a trailing slash, so make sure to add one), so that should solve your problem.
I'm closing this as it has nothing to do with Anchor itself, but if you need more help, just reply to the issue nevertheless.