Page 1 of 1

[SOLVED]Summary and Detail pages in modules

Posted: Sun Sep 27, 2015 1:03 pm
by jissey
Hello,
I'm working on EasyList.
With CMSMS 2.0 version, the default action summary works good but not the detail page (like in News module).
With SVN 2.0.1 version, the default action display nothing.
The php variable is not passed to the template :
$smarty->assign('items', $items);
echo $this->ProcessTemplateFromDatabase($summarytemplate);
In the template the smarty variable {$items} is empty.

What modification should I make between 2.0 and 2.0.1 version?

Thx

Re: Summary and Detail pages in modules

Posted: Sun Sep 27, 2015 2:49 pm
by Jo Morg
Yes I could reproduce this.
jissey wrote:$smarty->assign('items', $items);
echo $this->ProcessTemplateFromDatabase($summarytemplate);
Because of Smarty variable scope issues we were experiencing there were some changes made to CMSMS Smarty implementation. In most modules, where $smarty is already in scope inside the action method/files $this->ProcessTemplateFromDatabase() should work fine, but when a module overrides the DoAction() method of the CMSModule class, $smarty = cmsms()->GetSmarty() returns the global $smarty object instead of the current used template object so assigned variables will be out of current template scope.
On these cases, and following a Calguy1000 suggestion, I tested using a new (CMSMS 2.0.1+) module API method that returns the correct Smarty template object: $this->GetActionTemplateObject()...
So I would replace, where you override the CMSModule DoAction,

Code: Select all

$smarty = cmsms()->GetSmarty();
by

Code: Select all

$smarty = $this->GetActionTemplateObject();
HTH

Re: Summary and Detail pages in modules

Posted: Sun Sep 27, 2015 3:01 pm
by calguy1000
Just to follow up:

As of CMSMS 2.0.1:

For module action files (action.whatever.php) the correct smarty template object is available in scope as the $smarty variable. $this->ProcessTemplate(), and $this->ProcessTemplateFromDatabase() will work correctly.

Note: Those methods are deprecated.

If you feel you absolutely must use the global smarty object (usually you do not need to do this). Then you must call the fetch method on it yourself.

This change, and others were made because of a problem reported in 2.0 where a variable created in a parent template was not properly available in a child template.

Re: Summary and Detail pages in modules

Posted: Sun Sep 27, 2015 3:36 pm
by jissey
with

Code: Select all

$smarty = $this->GetActionTemplateObject();
it works but there is a warning :
Warning: Parameter 2 to SmartyBC::assign_by_ref() expected to be a reference, value given in lib\smarty\sysplugins\smarty_internal_templatebase.php on line 773

Re: Summary and Detail pages in modules

Posted: Sun Sep 27, 2015 3:40 pm
by Jo Morg
Replace all $smarty->assign_by_ref() with $smarty->assign(). There is no need to assign by reference anymore.

Re: Summary and Detail pages in modules

Posted: Sun Sep 27, 2015 4:01 pm
by jissey
That's ok now.
thx