[SOLVED] Get and display variables from objects / arrays with smarty

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Post Reply
jomoweb
Forum Members
Forum Members
Posts: 49
Joined: Wed Jan 31, 2007 9:27 pm

[SOLVED] Get and display variables from objects / arrays with smarty

Post by jomoweb »

I am having a tough time trying to extract variables from an array within an object. I am hoping that someone can help me figure out my issue and give me a quick run-down on how this to properly output variable values.

After doing a print_r dump of the Products object (I am working with the Products Module), I find the variable I am looking for and see the correct value.

In a node in $Products->cms->siteprefs, I find: [Products_mapi_pref_autopreviewimg] => 0

Code: Select all

{$Products->cms->siteprefs->Products_mapi_pref_autopreviewimg}
Outputs: Nothing

Code: Select all

{$Products->cms->siteprefs->Products_mapi_pref_autopreviewimg|print_r}
Outputs: 1 even though the value is 0

Code: Select all

{$Products->cms->siteprefs->Products_mapi_pref_autopreviewimg->value}
Outputs: nothing

Just for kicks, I tried to access some other variables in the same object.  Many of them behaved the same way, but some outputted the value correctly, like {$Products->cms->db->username}.  This has me completely confused  ???, and I would much appreciate a lesson in smarty / objects  :D.

Versions:
  • CMSMS: 1.6.7 "Teremba Bay"
  • PHP: 5.2.11
  • Apache: 2.0.63
  • Products: 2.4.8
  • CGExtensions: 1.17.8
  • CGSimpleSmarty: 1.4.3
Last edited by jomoweb on Thu Apr 08, 2010 12:53 am, edited 1 time in total.
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm

Re: Get and display variables from objects / arrays with smarty - help me?

Post by calguy1000 »

smarty array elements are accessed like
{$variable.keyname}  or {$variable[99]}

smarty object members are accessed like
{$object->membername}
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
jomoweb
Forum Members
Forum Members
Posts: 49
Joined: Wed Jan 31, 2007 9:27 pm

Re: Get and display variables from objects / arrays with smarty - help me?

Post by jomoweb »

Wow, from the module author himself, thanks! For the benefit of others reading, I also see that it you can combine traversers:

Code: Select all

$Products->cms->siteprefs.Products_mapi_pref_autopreviewimg

Good Smarty reference on the subject:
http://www.smarty.net/manual/en/languag ... iables.php
Last edited by jomoweb on Thu Apr 08, 2010 3:19 am, edited 1 time in total.
Post Reply

Return to “CMSMS Core”