Jump to content

{solved} Best approach for including files in subfolders with Markup regions


neophron
 Share

Recommended Posts

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?

Link to comment
Share on other sites

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'); ?>

 

Link to comment
Share on other sites

  • neophron changed the title to {solved} Best approach for including files in subfolders with Markup regions
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).

Link to comment
Share on other sites

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
Link to comment
Share on other sites

  • 3 weeks later...
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'); ?>

Link to comment
Share on other sites

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
 Share

×
×
  • Create New...