.php file not rendered in Editor

A recent requested change was made to Custom Component Devpacks which allowed you to have .php files in the templates folder whereas previously you could only have .html files. This change meant it was easier to edit PHP code files in an editor such as Nova as the syntax would be highlighted correctly.

However, a downside is that the Elements editor no longer renders these files now that the filetype has been changed to .php.

Can the editor be changed to treat .php files as .html files so that at least the HTML content renders?

I frequently encounter the same issue where custom components don’t render in the editor, forcing me to switch to preview mode. This does diminish the WYSIWYG principle of Elements. Are there guidelines to maximize rendering in Edit mode?

No, we’ve never rendered PHP in the editor.

Javascript and PHP only get run/rendered in the Browser Preview. This is a safety/security measure so the editor doesn’t get broken or messed with.

This is probably because you’re using Javascript in a Custom Component and that doesn’t get rendered in the editor.

@dan I understand that you don’t render PHP; what I am asking for is that you treat a .php file as if it where a .html file.

If I have PHP code in file that has a filetype of .html, the file renders OK, Elements ignores the PHP. This was working fine until I changed the filetype to .php in the the Custom Component template, to make the external editing easier in a Custom Component.

At the moment I have to flip the filetype back and forth, which while doable isn’t productive. :wink:

Oh! In that case it sounds like a bug, php files should be getting processed just like html files.

Can you send us the dev pack (or a sample) showing the bug? so we can look into it and get it fixed.

@dan I have emailed you some test files. :slight_smile:

1 Like

@dan: the @if(edit) is a good solution. Definitely to display the styling of a component in the editor. The preview mode can then be easily used for the data.

@logrunner Thanks for the file, I have tested it here and the PHP file is getting processed by Elements as you can see by the colour values changing when I preview it in Safari — Is this not what you get?

Edit: we’re just looking into this further… to see if we can improve things.

@dan, just to clarify what I meant. Yes it is working for me in safari, that isn’t the issue.

It isn’t working in the Editor. The only difference between the two Components (PHP Test and HTML Test) is the filetype in the Components Template folder. Both components contain PHP code. If I change the PHP Test Component to have a filetype of .html in the Template folder it renders in the Editor OK, regardless of the fact that the now .html file contains PHP code.

I am requesting that if the editor sees a .php file, it treats it as .html and renders it in the Editor. :slightly_smiling_face:

1 Like

Yup, understood :+1: I have added this high-up on the bug list to take a look at!

@logrunner give beta 34 a whirl and let us know if the html rendering in PHP components is now working for you :pray:

Hi @dan, Yes, it does. Thanks for sorting that out. :grinning: