• twitter image
  • facebook image
  • youtube image
  • linkedin image
Language: CMS Made Simple Czech CMS Made Simple France CMS Made Simple Spain CMS Made Simple Hungary CMS Made Simple Russia CMS Made Simple Netherlands

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: noob to smarty, UDT writing needs a little coaching
PostPosted: Thu Apr 14, 2011 1:50 pm 
Offline
New Member

Joined: Thu Apr 14, 2011 1:33 pm
Posts: 3
My end goal is to pass the page alias into my UDT which will then make related database queries.

Trying to get a handle on how to communicate between smarty/php.

I see lots of examples of UDT's where there's:

Code:
global $gCms;


but no references as to what this global var is. I'm assuming it's a reference to the 'scope' of the CMS/smarty itself (?)

I know you can pass params in via the tag:
Code:
 {content assign=pagecontent}
  {table_of_contents thepagecontent="$pagecontent"}


but i'm not sure where to look to find out (reference) what smarty variables are available to pass in ( i see that 'content' is assigned to a php variable and passed in directly to the UDT in the above example )

any help would be great!


Top
 Profile  
 
 Post subject: Re: noob to smarty, UDT writing needs a little coaching
PostPosted: Thu Apr 14, 2011 3:53 pm 
Offline
New Member

Joined: Sat Apr 09, 2011 10:24 am
Posts: 2
The $gCms is a global object for CmsObject class. You need it to get a reference to the ADODB-object when you're about to make queries to the database, e.g.
Code:
global $gCms;
$db =& $gCms->GetDb(); // an ADODB-object reference. Notice that we're using only a reference and thus not creating a new object in memory.

// Now when we have $db available, we can do queries like this:
$query = "SELECT * FROM myspecialtable WHERE username = ?";
$result = array();
$rs = $db->Execute($query,$params['username']);
if($rs && $rs->RecordCount() > 0) {
    $result = $rs->GetArray();
}
echo '<pre>';
print_r( $result );
echo '</pre>';

Notice that there's the special array, called $params, I'm using. It hold's the variables you have inputted to your UDT. So if I wanted to get all the results from myspecialtable where field username has the value "Bob", I'd call my UDT like this:
Code:
{myudt username='Bob'}


I hope this answer is what you needed.


Top
 Profile  
 
 Post subject: Re: noob to smarty, UDT writing needs a little coaching
PostPosted: Thu Apr 14, 2011 3:56 pm 
Offline
New Member

Joined: Sat Apr 09, 2011 10:24 am
Posts: 2
Oh, and have you read this? http://wiki.cmsmadesimple.org/index.php ... fined_Tags

It helps you making your own UDT's


Top
 Profile  
 
 Post subject: Re: noob to smarty, UDT writing needs a little coaching
PostPosted: Thu Apr 14, 2011 5:36 pm 
Offline
Power Poster
Power Poster
User avatar

Joined: Tue Dec 23, 2008 8:39 pm
Posts: 1316
$gCms is an instance of the CmsObject class: http://www.cmsmadesimple.org/apidoc/CMS/CmsObject.html

You can use {get_template_vars} to see all smarty variables available to your template.


Top
 Profile  
 
 Post subject: Re: noob to smarty, UDT writing needs a little coaching
PostPosted: Fri Apr 15, 2011 3:44 pm 
Offline
New Member

Joined: Thu Apr 14, 2011 1:33 pm
Posts: 3
thanks for the excellent responses guys! I'm beginning to get a handle on the whole smarty/UDT tag thing.

If i wanted to pass in a template var (page_alias) to my UDT, how would i go about that? (I haven't found an example yet)

{myUDT myVar=page_alias}

Ultimately i want to query a separate/non-cms database using the page_alias/product name


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
A2 Hosting