How can I stop Hugo from escaping out my PHP code in a template file?

I’m using Hugo for a website, which is mostly static content but which contains some PHP pages. I’ve followed this guide to set up some PHP compatibility, and with shortcodes it works fine.

But for some major pages I want to have PHP content in the template files, and this is where I’m running into trouble. For example, I have an index.php template, and when I build the project, <?php gets changed to &lt;?php. Even worse, if I mix in PHP inside HTML attributes, the project won’t even build at all as Hugo complains about an error while rendering the HTML.

How can I get Hugo to just leave my template alone? Or do you have any other suggestions? Thanks.

Can you show your repo?

How about creating a shortcode that adds the php tags before and after the content of the shortcode?

So, the templates don’t work. I wonder if that’s a bug (since you’re declaring them/it as php) or, if you need to pipe the strings to safeHTML.

2 posts were split to a new topic: Escape PHP code in template