[SOLVED] Getting a variable from an included file to CMSMS

The place to talk about things that are related to CMS Made simple, but don't fit anywhere else.
Post Reply
sanderhartveld
Forum Members
Forum Members
Posts: 25
Joined: Mon Sep 07, 2009 10:33 am
Location: Bloemendaal, Netherlands

[SOLVED] Getting a variable from an included file to CMSMS

Post by sanderhartveld »

Hi,

I have a UDT that looks like this:

Code: Select all

include("antwoorden.php");
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:

Code: Select all

{$firstname}
But the output is nothing. How can I pass a variable from antwoorden.php to my template?
Thank you.

Sander
Last edited by sanderhartveld on Thu Oct 30, 2014 10:27 am, edited 1 time in total.
JohnnyB
Dev Team Member
Dev Team Member
Posts: 729
Joined: Tue Nov 21, 2006 5:05 pm
Location: OH, USA

Re: Getting a variable from an included file to CMSMS

Post by JohnnyB »

I think you are missing this to assign to smarty

// send to Smarty
$smarty = cmsms()->GetSmarty();
"The art of life lies in a constant readjustment to our surroundings." -Okakura Kakuzo

--
LinkedIn profile
--
I only speak/write in English so I may not translate well on International posts.
--
sanderhartveld
Forum Members
Forum Members
Posts: 25
Joined: Mon Sep 07, 2009 10:33 am
Location: Bloemendaal, Netherlands

Re: Getting a variable from an included file to CMSMS

Post 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.
JohnnyB
Dev Team Member
Dev Team Member
Posts: 729
Joined: Tue Nov 21, 2006 5:05 pm
Location: OH, USA

Re: Getting a variable from an included file to CMSMS

Post 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/
"The art of life lies in a constant readjustment to our surroundings." -Okakura Kakuzo

--
LinkedIn profile
--
I only speak/write in English so I may not translate well on International posts.
--
User avatar
Rolf
Power Poster
Power Poster
Posts: 7825
Joined: Wed Apr 23, 2008 7:53 am
Location: The Netherlands
Contact:

Re: Getting a variable from an included file to CMSMS

Post by Rolf »

Path to the PHP file is correct?
- + - + - + - + - + - + -
LATEST TUTORIAL AT CMS CAN BE SIMPLE:
Migrating Company Directory module to LISE
- + - + - + - + - + - + -
Image
Jeff
Power Poster
Power Poster
Posts: 961
Joined: Mon Jan 21, 2008 5:51 pm
Location: MI

Re: Getting a variable from an included file to CMSMS

Post 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
sanderhartveld
Forum Members
Forum Members
Posts: 25
Joined: Mon Sep 07, 2009 10:33 am
Location: Bloemendaal, Netherlands

Re: [SOLVED] Getting a variable from an included file to CMS

Post 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.
User avatar
Jo Morg
Dev Team Member
Dev Team Member
Posts: 1922
Joined: Mon Jan 29, 2007 4:47 pm

Re: [SOLVED] Getting a variable from an included file to CMS

Post 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.
"There are 10 types of people in this world, those who understand binary... and those who don't."
* by the way: English is NOT my native language (sorry for any mistakes...).
Code of Condut | CMSMS Docs | Help Support CMSMS
My developer Page on the Forge
GeekMoot 2015 in Ghent, Belgium: I was there!
GeekMoot 2016 in Leicester, UK: I was there!
DevMoot 2023 in Cynwyd, Wales: I was there!
Post Reply

Return to “The Lounge”