Hugo markup render <?php to <!--?php

How can I get the <?php and ?> Instruction in a shortcode without the generator commenting it out? My Hugo version is 0.83.1

config.toml:
[markup]
[markup.goldmark]
[markup.goldmark.renderer]
unsafe = true

Shortcode php.html:
{{ .Inner | safeHTML }}

test.md:
{{< php >}}
<p>HTML hello</p>
<?php
echo 'The current PHP version is ' . phpversion();
?>
{{< /php >}}

After Hugo has created the static page, the code looks like this:
<p>HTML hello</p>
<!--?php
echo 'The current PHP version is ' . phpversion();
?-->

I am unable to reproduce the problem. The shortcode renders as:

<p>HTML hello</p>
<?php
echo 'The current PHP version is ' . phpversion();
?>

Do you have a repository we can look at?

Thanks for the answer. I’ll send you a private Google Drive link. There you can view the complete project. You can find the test code at localhost:1313/kontakt. In the English version I have not yet inserted the test code.

Try converting the php tags to a string and piping them with the safeHTML function.

{{- print "<?php" | safeHTML }}
echo 'The current PHP version is ' . phpversion();
{{- print "?>" | safeHTML }}

Thank you for your answer. But that makes things worse:

I still cannot reproduce the problem with the project you privately shared.

kontakt/index.html

...
<p>HTML hello</p>
<?php  
echo 'The current PHP version is ' . phpversion();
?>  
...

Thanks for looking at the code. Strange, did you call up the German contact page via the menu? kontakt/index.html is actually not correct. Have you looked at the source code of the HTML page?

I looked at /kontakt/index.html in the public directory. There is actually no comment out there. In the browser, when outputting, the PHP part is commented out. Now I don’t understand anything anymore. Tried it with Firefox, Chrome and Safari.

image

What does this mean? Are you visiting http://localhost:1313/kontakt/, or are you serving the site with Apache/NGINX/other?

Both. I have a local MAMP server environment - same error. The password-protected website on the Internet - same mistake. Pure localhost:1313 solution with Hugo - same error. In /kontakt/index.html there is no comment out in any environment. It’s not because of Hugo and the markup. The browser, like Firefox, Chrome and Safari, output the code commented out. ???

Are you sure that your MAMP and production servers are configured to interpret HTML pages as PHP pages? I am not commenting on the security merits of this configuration…

OK that’s it. I have to come up with something else. Still, why is the PHP code commented out in a pure Hugo environment? Thanks for your help, I’ve taken it too long. Will mark the request as resolved.

In all of my testing, it is not.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.