All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.
I need some quick Nginx help. (Executing PHP in .tpl files)
Well, I'm running a very basic Nginx/PHP server for a flat file blog with a template system based on the smarty framework.
I've tried wrapping the PHP code in {literal}{/literal} and {php}{/php} tags in the .tpl file, and no go.
Seems that those on apache can amend .htaccess with
AddType application/x-httpd-php .tpl
And it 'should' work.
I was always horrible at trying to convert .htaccess rules to shit nginx will execute, so, can anyone help a dude out?
EDIT: I should have read more of the documentation. I figured it out.
I was literally wrapping PHP in the {php}{/php} tags, I didn't realize you had to (for example) do this: https://pastebin.com/4JxMUuu1 ( I tried sharing that example but kept getting Cloudflare popups trying to tell me I was blocked from the site. Guess you can't put php code in forms.)
Comments
When I pasted the example PHP code I got a popup saying I was blocked from LowEndTalk. Must have been a cloudflare thing. Element inspector let me exit out of it, and I'm not blocked, I guess. So, that was weird.
Anyway, yeah. Any help would be greatly appreciated.
@MannDude If I am understanding it right, basically you are trying to run .tpl extension files as .php ?
Could try adding to mime.types file in nginx config dir
application/php tpl;
I don't know that it works... it just looks the same as apache
AddType application/x-httpd-php .tpl
EDIT: and add tpl to the location
and add to php-fpm.conf:
security.limit_extensions = .php .tpl
Please refer to official documentation that might help you:
https://www.nginx.com/resources/wiki/start/topics/examples/full/#mime-types
Thanks everyone
I got it figured out about 5 minutes after I made my original post. I needed to include a php file in the footer of a template (footer.tpl) and it had been years since I've done this. I was wrapping the php code in {php}{/php} tags in the tpl file, since that's standard formatting for the smarty php template engine BUT I was doing it incorrectly. The {php}{/php} tags replace the standard
<? ?>
brackets, it doesn't surround them.In the end I didn't need to modify anything on the webserver side of things, it was already good to go.
Guess I was just tired.
It is so wrong to execute php code in template file. Why do you need such action? Write plugin or smarty action. Do not mess presentation layer.
Just needed to call a lame ass hit counter into the page. Needed to include 'counter.txt' since it updates with each new page view. Pretty dumb but it's a low traffic site that will be seen by practically no one.
Take a note, that tpl files generate cache, where your php code can be exposed to third parties. Probably even manipulated.