Problem with PHP include in HEAD section

======== TEMPLATE BUG FORM ========

Wappler Version : 2.6.1
Operating System : Windows 10

Expected behavior

Saving a page should not cause the code to be altered/reformatted. (The Format Document on save option is not selected.)

Actual behavior

The contents of the <HEAD> section are changed and double-spacing is applied.

How to reproduce

Open a page with a PHP include in the <HEAD> section and save it.

Eg this is part of a page I created few months ago:

image

I opened it to make a minor change and saved it. This was the result:

There have been various problems including PHP in files before, but I haven’t come across an issue quite like this one. I’ve only just encountered the problem but the issue might have been introduced before 2.6.1.

This is a known issue. Currently we can’t process PHP includes in head as they break the the whole head in our DOM parser.

So we advice not to use php includes in the head.

All other places are just fine and doesn’t give any problems.

But it wasn’t an issue when I created the site in question. I could save pages without any problem then - not very long ago. I’m sure I did everything in Wappler.

I was adding some Google Analytics code, which I had put in an include. I think it’s recommended that this code is included before any other css/js. I thought I would add the Javascript code in directly, but the code was rewritten anyway, because I had already used an include. I’ll have to add a lot of extra lines unnecessarily to each page in this site to be able to use it in Wappler. For the time being I’ll use a text editor and just add the extra line.

Is this likely to be fixed soon?

Google Analytics code shouldn’t be in your head but at the end of the body.

The PHP Include in the head won’t be fixed soon as we will need to rewrite our whole html parsing and synchronization with code view. We do plan to eventually use a different HTML5 parser that isn’t that strict (comments/text nodes like PHP aren’t valid in HTML5 …) but it will take time to implement.

1 Like

The owner of the website concerned is using Google Tag Manager. He sent me the code which, according to Google’s documentation, should be placed in the <head> section:

image

Is there another way to include a file in the <head> section if PHP doesn’t work?

I have the same question. Why not using SSI include? I don´t understan the difference between PHP include and SSI include (and I´ve read the posts about the difference).

From what I understood about the difference, I´ve concluded that activating SSI includes on a server is not convinient or hard to do.

Can you guys test this with the latest beta?
The handling of PHP code in the head should be improved now.

I’ve just tested this, with beta 5.

PHP includes in the head section no longer cause the layout to be messed up. This is a great improvement and will be really helpful.

However, there are still issues using Wappler with non-Wappler sites. Eg saving a file containing this line:
<a href="stock_detail.php?stockid=<?php echo($rs_stock->getColumnVal('stock_id')); ?>">
… results in:
<a href="stock_detail.php?stockid=+++++++++++++++++++++++++++++++++++++++++++++++++++">

It would be nice to be able to edit any PHP in Wappler, but it’s not much of an issue as it only affects old sites obviously. (It was quite an issue on the occasions I’ve forgotten, and have uploaded a page with quite a lot of PHP like this.)

We will improve it further in the next beta.

1 Like

It is improved, but still not quite there.

Nothing is actually lost now, which is great - but it’s just encoded when it shouldn’t be:
Eg this line:
<link href="css/custom.css?<?php echo filemtime('css/custom.css');?>" rel="stylesheet">
… becomes:
<link href="css/custom.css?%3C%3Fphp+echo+filemtime%28%27css%2Fcustom.css%27%29%3B%3F%3E" rel="stylesheet">
… when the document is saved.

However, in some cases, the original line is not changed:
<?php echo($rs_stock_featured->getColumnVal('title')); ?>

… but similar lines are changed, when they are enclosed in <a> tags:
<a href="stock_detail.php?stockid=<?php echo($rs_stock->getColumnVal('stock_id')); ?>">
…becomes:
<a href="stock_detail.php?stockid=%3C%3Fphp+echo%28%24rs_stock-%3EgetColumnVal%28%27stock_id%27%29%29%3B+%3F%3E">

I see - yes we do some more url rewrites on save and have to improve those as well

1 Like

Does this is fixed now?