for a long time I have been using a snippet to include external files as templates and chunks. I found this snippet in an older forum. But since I’ve been working with Modx 3 and PHP 8, the snippet no longer works. It works only one my frontpage but the subpages are all blank pages now.
This is the snippet I have used so far:
<?php
# Snippet to include template files from file system
# usage: [[includeTemplate? &tpl=`template.tpl`]]
if (!isset($tpl)||$tpl=="") return "Missing Template file!";
$tpl = $base_path .'assets/templates/page/'.$tpl;
ob_start();
include($tpl);
return ob_get_clean();
I think this code has just to be updated for php 8. Is there anyone who could help me with this?
Thank you Harry,
I have changed this as you wrote, but I still have the same issue with the subpages. They all are still blank.
In PHP 7.4 I don’t have this issue. Could it be that because of PHP 8 I have to adapt the code somehow? Unfortunately, I am not familiar with PHP. So far I have done very little.
Or have I done something wrong with this? $tpl = $modx->getOption('base_path') .'assets/templates/page/'.$tpl;
I have tried to reproduce this with MODX 3.0.1 and PHP 8, but the snippet works correctly on my installation.
To my knowledge nothing in this snippet code shouldn’t work with PHP 8.
What exactly do you mean by subpages? Just resources further down in the resource tree or is there something special about them?
Could you rewrite the whole code so that it would work with PHP 8?
What I mean with Subpages: “further down in the resource tree”. That code works only on the startpage. All others are blank.
You can see it here. - This is a page of my old neighbour.His provider wants to switch off PHP 7.4 in November so that I have to fix that code.
I have been helping him for years for free but this is over my skils
You don’t have to do it for free. I would even donate a coffee to you or someone else via Paypal if you agree.
Ps: I tried the static solution from Modx before in another project, and then I saw that I would have to rebuild everything in this projekt (link) because the nested templates would no longer work.
As I wrote, I don’t get anything from that and I’m tired to start everything again.
In my opinion there is nothing to rewrite here.
My guess is that there is something else (another snippet, maybe a plugin) that doesn’t work with PHP 8.
When I open one of your subpages, I can see (in the browser’s developer tools) that it returns a 500 Internal Server Error.
Please try to locate the PHP error log on your server to check the actual error message. (This is not the error log inside MODX. The exact location depends on the server configuration.)
Thanx a lot Harry for your time and effort!
I’ll have a look at the plugins. Maybe I can locate the error there. If a snippet or plugin is causing the problem I will get back to you and this topic can be closed than.
Hi Bob,
I have just done what you and Harry said and I found out that none of the plugins I use cause this error. It was a Snippet called “siblingsnav” - a prev next navigation from
bruno17. I will check on githup if this problem is already known and report it if necessary.
Thanx for all of your help!
Oh wow - his change in the code solved my problem in no time.
I think Bruno will update this in the package in the near future.
Thanx a lot again, Harry!