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?
@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.
@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.