[英]how to add php code in .tpl file in prestashop
Does anyone know how to add php code in .tpl
file in prestashop..i tried a lot but couldn't find any solutions..I want to add a mail function in my .tpl
file 有谁知道如何添加PHP代码中
.tpl
在prestashop..i文件尝试了很多,但找不到任何solutions..I想在我添加邮件功能.tpl
文件
This is the function 这是功能
<?php
$name=$_REQUEST["name"];
$email=$_REQUEST["email"];
$matter=$_REQUEST["matter"];
$subject=$name."has shared a weblink";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$contactMsg = '
<html>
<head>
<title>Tell A Friend</title>
</head>
<body>
<table>
<tr>
<td>E-mail: '.$email.' </td>
</tr>
<tr>
<td>Comment: '.$matter.' </td>
</tr>
</table>
</body>
</html>
';
$headers .= "from:abcd" . "\r\n";
$headers .= "To: Info <info@abcd.in";
$headers .= "reply-to:".$email."\r\n";
$headers .= "Cc:".$email."\r\n";
$headers .= 'Bcc: ' . "\r\n";
if(mail($email, $subject, $contactMsg, $headers))
{
$_REQUEST = array();
$error.="Mail Sent Successfully";
}
else
{
$error.="Error Mail Sent Fail!";
//
}
?>
i tried writing the code inside {php}
{/php}
block..but couldn't help And how to see the error log
in prestashop
我试着在
{php}
{/php}
块中编写代码。但是无济于事,如何在prestashop
查看error log
You can edit the controller file, eg. 您可以编辑控制器文件,例如。 if you want to add the form in a cms page, you have to edit this /controller/CMSController.php
如果要在cms页中添加表单,则必须编辑此/controller/CMSController.php
edit this 编辑这个
public function displayContent()
{
parent::displayContent();
self::$smarty->display(_PS_THEME_DIR_.'cms.tpl');
}
with this 有了这个
public function displayContent()
{
IF ($_POST['submit_form']==1){
// here submit action mail() for example
}
parent::displayContent();
self::$smarty->display(_PS_THEME_DIR_.'cms.tpl');
}
it's better to add php
functions classes etc in your module controller, 最好在模块控制器中添加
php
函数类,
{php}
is depreciated for a reason as it allow poor practices. {php}
之所以贬值,是因为它允许不良做法。 Smarty recommends putting the included script into the PHP logic (controllers,classes,functions)
Smarty建议将随附的脚本放入PHP逻辑
(controllers,classes,functions)
The use of the {php}{/php} tags in .tpl files is turned off in somme versions of Prestashop 在Prestashop的某些版本中,.tpl文件中的{php} {/ php}标签的使用已关闭
I had the same problem using Prestashop 1.5.4.1 To turn it on make changes in the file config/smarty.config.inc.php : 我在使用Prestashop 1.5.4.1时遇到了相同的问题,要在文件config / smarty.config.inc.php中打开它进行更改:
find these lines (line 27 to line33) 找到这些行(第27行到第33行)
...
define('_PS_SMARTY_DIR_', _PS_TOOL_DIR_.'smarty/');
require_once(_PS_SMARTY_DIR_.'Smarty.class.php');
global $smarty;
$smarty = new Smarty();
$smarty->setCompileDir(_PS_CACHE_DIR_.'smarty/compile');
...
change it to 更改为
...
define('_PS_SMARTY_DIR_', _PS_TOOL_DIR_.'smarty/');
require_once(_PS_SMARTY_DIR_.'SmartyBC.class.php');
global $smarty;
$smarty = new SmartyBC();
$smarty->setCompileDir(_PS_CACHE_DIR_.'smarty/compile');
...
...shortly, use SmartyBC.class.php instead of Smarty.class.php ...不久,请使用SmartyBC.class.php而不是Smarty.class.php
(warning: using {php}{/php} tags in template files is deprecated in Prestashop!) (警告:Prestashop中不建议在模板文件中使用{php} {/ php}标签!)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.