Before diving into any server-related configuration issues, I'd try changing the extension to .inc, which PHP will see as HTML with optional PHP. If that doesn't work, message back with how you are loading the .phtml file.
.phtml alternative file extension ~ Legacy to Laravel
Greetings. Thank you for reading.
I'm just beginning my Laravel learning journey. One of my first project goals has been to update a legacy app to function as a Laravel app. The first hurdle I've encountered is that the legacy app uses file extension .phtml for some files, as a means of differentiating the way the files will load for a given view.
The legacy PHP "app" is a simple static content viewer. Maybe think of it as a VERY simplified version of something like DokuWiki. I created it about 20 years ago to browse static content on a development server. The navigation uses a JavaScript onclick event to send some filetypes to an iframe (e.g. to preview images, html, txt files. etc.). That is, this legacy app doesn't really use a database but instead is more about dealing with file paths and file types.
Files with a .php file extension intentionally DO NOT load in the HTML iFrame, but PHP files with a .phtml extension ARE meant to load in the iframe. This method has worked for me for instance if I have some files in a folder, and I want to make a note about those files, or setup something with PHP / JavaScript etc (e.g. a screenshot slideshow), i can do that and have the results load in the iFrame if it has the .phtml file extension. It's been a very simple way to achieve the desired result (targeting the iframe with a specific filetype, based on file extension).
I find that I can't reuse any of the existing .phtml files because Laravel doesn't render it (not surprising necessarily that Laravel doesn't recognize that the .phtml files are actually PHP files), so the .phtml files are displayed as HTML where there is HTML in the files, while the PHP parts of course just come through as the raw PHP code.
Is there a common Laravel configuration file(s) where I can modify settings to tell Laravel to render .phtml files like any "normal" php?
My development server is powered by NGINX / php8.2-fpm. I have it configured to serve/ render the .phtml files as desired but as far as I understand at this time, Laravel is not cooperating.
Thank you!
It doesn’t sound like your old project is structured in a way that is in any way comparable to (or compatible with) Laravel.
You can’t fix this in your Nginx setup, because using Laravel, only one PHP file is ever actually served: index.php. Everything else is handled internally by Laravel.
If you want to use your old .phtml files as what is actually shown on the page, you could:
- rename the files to
.blade.phpinstead of.phtmlas @snapey says - create routes to the relevant endpoints for all these files
- return the view corresponding to the page in question from the route
That still won’t give you the whole iframe thing, though. There’s no simple way to get that, because that’s just not how Laravel is structured. Unless what you mean is that you previously had an outer main page with links that then loaded inside the iframe – that would of course still work, you’d just change those links to point to the Laravel routes.
Please or to participate in this conversation.