Page 1 of 1
[SOLVED] Getting a variable from an included file to CMSMS
Posted: Sat Oct 25, 2014 6:35 pm
by sanderhartveld
Hi,
I have a UDT that looks like this:
Inside antwoorden.php I try to define a variable using:
Code: Select all
$smarty->assign('firstname', 'Doug');
The UDT is called inside a content block on a page.
In my page template I am using:
But the output is nothing. How can I pass a variable from antwoorden.php to my template?
Thank you.
Sander
Re: Getting a variable from an included file to CMSMS
Posted: Mon Oct 27, 2014 12:58 pm
by JohnnyB
I think you are missing this to assign to smarty
// send to Smarty
$smarty = cmsms()->GetSmarty();
Re: Getting a variable from an included file to CMSMS
Posted: Mon Oct 27, 2014 6:08 pm
by sanderhartveld
Thank you. This works in CMSMS 1.10.3.
I did see that in the documentation but I did not try because on
http://docs.cmsmadesimple.org/tags/user ... ting-a-udt it says
As of CMSMS version 1.11 it is invalid to overwrite the $smarty object that is passed in to the UDT with the global smarty object.
In example in a User Defined Tag this code is invalid and will cause errors:
$smarty = cmsms()->GetSmarty()
Do I need to take this into account when upgrading? Is there also another approach that will continue to work in 1.11?
Also, I want to use the variable in the head of the template before the UDT is called trough the content block. Is that possible? Now it shows nothing.
Re: Getting a variable from an included file to CMSMS
Posted: Mon Oct 27, 2014 7:25 pm
by JohnnyB
You would need to put your UDT before the <head> if you want to use a var from it early on...
I think it still works with 1.11.x -- I might be wrong so hopefully someone else will confirm or deny that.
As far as 2.0 -- you'll probably need something different. I haven't really done much with it yet, but there's
http://www.cmsmadesimple.org/APIDOC2_0/
Re: Getting a variable from an included file to CMSMS
Posted: Tue Oct 28, 2014 8:29 am
by Rolf
Path to the PHP file is correct?
Re: Getting a variable from an included file to CMSMS
Posted: Wed Oct 29, 2014 12:43 am
by Jeff
JohnnyB wrote:You would need to put your UDT before the <head> if you want to use a var from it early on...
Unless you changed the order of the template processing, the < body> is processed before <head> so the variable should be avaliable.
Jeff
Re: [SOLVED] Getting a variable from an included file to CMS
Posted: Thu Oct 30, 2014 10:28 am
by sanderhartveld
Thank you all. I found that it actually does work without putting the UDT before the head. Well see later on what happens when I upgrade.
Re: [SOLVED] Getting a variable from an included file to CMS
Posted: Thu Oct 30, 2014 10:31 am
by Jo Morg
sanderhartveld wrote:Well see later on what happens when I upgrade.
Then you will have to remove:
$smarty = cmsms()->GetSmarty(); from the UDT.