I
I
Ivan Gorokhov2015-09-10 08:32:29
PHP
Ivan Gorokhov, 2015-09-10 08:32:29

Problem migrating from Smarty 2 to Smarty 3?

The question is quite simple, I can not transfer the script to the new version of the template engine.
I used to have this code

function emailtpl_template($tpl_name, &$tpl_source, Smarty $smarty_obj)
{
  $tpl_source = $smarty_obj->get_template_vars($tpl_name);
  return empty($tpl_source) ? false : true;
}

function emailtpl_timestamp($tpl_name, &$tpl_timestamp, Smarty $smarty_obj)
{
  return true;
}

function emailtpl_secure($tpl_name, Smarty $smarty_obj)
{
  return true;
}

function emailtpl_trusted($tpl_name, Smarty $smarty_obj)
{
}

$smarty = new Smarty();
$smarty->compile_id = md5($subject . $message . (defined("IN_CRON") ? "cron" : ""));
$smarty->register_resource("emailtpl", array("emailtpl_template", "emailtpl_timestamp", "emailtpl_secure", "emailtpl_trusted"));
$smarty->assign("emailsubject", $subject);
$smarty->assign("emailmessage", $message);
$smarty->assign("plaintext", $message_text);

foreach ($email_merge_fields as $mergefield => $mergevalue) {
  $smarty->assign($mergefield, $mergevalue);
}

$subject = $smarty->fetch("emailtpl:emailsubject");
$message = $smarty->fetch("emailtpl:emailmessage");
$message_text = $smarty->fetch("emailtpl:plaintext");

But in Smarty 3, the register_resource function was changed to registerResource,
I replaced it in my code, but the script began to give me an error
Fatal error: Uncaught --> Smarty: Unable to load template emailtpl 'emailsubject' <-- thrown in W:\domains\test\Smarty\sysplugins\smarty_internal_template.php on line 138

But before the transition, everything worked. tell me what to do to get started.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
LeMaX, 2015-09-10
@Dead_Angel

In Smarty 3, the registerResource method no longer accepts an array of functions.
It now accepts a successor to the abstract Smarty_Resource class.
www.smarty.net/docs/en/api.register.resource.tpl

M
Mikhail Opanasenko, 2015-12-03
@Maxmadknight

$smarty->registerResource("emailtpl", array("emailtpl_template", "emailtpl_timestamp", "emailtpl_secure", "emailtpl_trusted"));

In the 6th version of WHMCS, they changed the environment
. As a result, you need to specify as the second parameter not a string array, but an array of resource objects, does anyone know which resources to specify?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question