Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add PHP code to .tpl file [duplicate]

Tags:

php

smarty

I need to display some external data from php file to .tpl file. For this I want to include php file to .tpl file. I have tried folllowing code to display php file content to tpl.

{php} include('custom_code.php'); {/php}

but on page output was include('custom_code.php');

like image 501
absolutek Avatar asked Mar 07 '12 12:03

absolutek


2 Answers

{php} has been deprecated. Have a look at Extending Smarty With Plugins.

put the follwing in …/plugins/function.yourplugin.php:

<?php
function smarty_function_yourplugin(array $params, Smarty_Template_Instance) {
    include 'your_other_file.php';
}

and use in your template:

{yourplugin}
like image 125
rodneyrehm Avatar answered Oct 22 '22 20:10

rodneyrehm


You shouldn't add PHP code to the template. It will make whole idea of templates spoiled.

You have to add PHP code to controller, not template.

like image 37
Your Common Sense Avatar answered Oct 22 '22 20:10

Your Common Sense