Jump to content

Recommended Posts

Posted

Hi guys,

I'm struggling with including php files from a subfolder. Maybe because there are more then one solution.
I'm using the $config->useMarkupRegions = true; with the _main.php. Right now I have some php files that I include in the template files like this: <?php include('menu_main.php'); ?>

Now I have this subfolder: /templates/includes
This won't work: <?php include('includes/menu_main.php'); ?>
Using <?php wireIncludeFile('includes/menu_main.php'); ?> works only with the menu_main.php file, but not with others. 

What would you suggest?

Posted
21 hours ago, BitPoet said:

Give wireRenderFile a try instead of wireIncludeFile.

Thanks.

I think I found the error: It's the famous <?php namespace ProcessWire;

Solution: 
all included php files should start with a <?php namespace ProcessWire;
And in my case now it looks like this:

<?= wireIncludeFile('includes/menu_main.php'); ?>

 

  • neophron changed the title to {solved} Best approach for including files in subfolders with Markup regions
Posted
3 hours ago, BitPoet said:

Give wireRenderFile a try instead of wireIncludeFile.

Using wireRenderFile doesn't render the stuff. Using wireIncludeFile works right now.
No idea what's wrong cause there are no errors (even with tracy).

Posted
5 minutes ago, neophron said:

Using wireRenderFile doesn't render the stuff. Using wireIncludeFile works right now.
No idea what's wrong cause there are no errors (even with tracy).

Ah, should have mentioned that. wireRenderFile returns the rendered content, so you need to echo it or use <?= wireRenderFile(...) ?>.

 

  • Like 1
  • 3 weeks later...
Posted
On 10/30/2023 at 2:35 PM, BitPoet said:

Ah, should have mentioned that. wireRenderFile returns the rendered content, so you need to echo it or use <?= wireRenderFile(...) ?>.

 

Now for everybody, who looks how to include files from a subdirectory:
In site/templates/includes/menu_main.php render the file by: <?php echo wireRenderFile('includes/menu_main.php'); ?>

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
×
×
  • Create New...