making my *.tpl file look different if!

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
jmansa
Forum Members
Forum Members
Posts: 126
Joined: Thu Oct 19, 2006 2:46 pm

making my *.tpl file look different if!

Post by jmansa »

Is it possible to make a tpl file look different depending on certain data.. I have a table with some options and I want the tpl to look different if certain fields a filled like they way its uses in php..

PHP example!

Code: Select all

if ($course['holes_18'] == '1') {
echo 'Some fields here';}
elseif ($course['holes_36'] == '1') {
echo 'Some other fields here!'}
Is that possible to do inside the 'tpl file, and if yes... How?
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: making my *.tpl file look different if!

Post by calguy1000 »

tpl files are smarty templates, see http://smarty.php.net/manual/en
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.
jmansa
Forum Members
Forum Members
Posts: 126
Joined: Thu Oct 19, 2006 2:46 pm

Re: making my *.tpl file look different if!

Post by jmansa »

Thanks alot... Thats just what I needed, but have 1 question though!

How can I "print" a title from my db instead of my language file?

$this->smarty->assign ('title', $this->Lang ('editcourse'));

Trying to do something like this but nothing comes out?

$this->smarty->assign ('title', $this->$course['club_name']));

Can somebody please help?
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: making my *.tpl file look different if!

Post by calguy1000 »

I take it your doing some programming then.  How's your PHP foo?  You didn't provide many details as to what you're trying to do, or what code your fooling with so I have to guess.

Here's a quick example of how to do some querying in CMS.  This example gets a single row from some_table, and then assigns each field in the resulting row to smarty.

Code: Select all

$query = 'SELECT * FROM some_table WHERE id = ?';
$row = $db->GetRow( $query, array($recordid) );
if( $row )
 {
    foreach( $row as $key => $value )
       {
           $smarty->assign($key,$value);
       }
 }
This is a simple generic example, there's may different ways to do it.
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.
jmansa
Forum Members
Forum Members
Posts: 126
Joined: Thu Oct 19, 2006 2:46 pm

Re: making my *.tpl file look different if!

Post by jmansa »

This is what I have done so far:

Code: Select all

    $query =
      "SELECT * FROM ".cms_db_prefix ().
      "module_clubmanager_clubs WHERE uid = ?";
    $dbresult = $db->Execute ($query, array($params['uid']));

    $course = $dbresult->FetchRow ();
	
	$this->smarty->assign ('title', $this->$course['club_name']));
Hope that helps!
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: making my *.tpl file look different if!

Post by calguy1000 »

Okay, I'm not sure if you're in a UDT, or inside an action of a module you're writing... but anyways

if you're in a UDT, you'll need this code:

Code: Select all

global $gCms;
$smarty =& $gCms->GetSmarty();
Then this should do it:

Code: Select all

$smarty->assign ('title', $course['club_name']);
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.
jmansa
Forum Members
Forum Members
Posts: 126
Joined: Thu Oct 19, 2006 2:46 pm

Re: making my *.tpl file look different if!

Post by jmansa »

Thanks alot... That was it!:-) I'm trying to create a module.
User avatar
Dr.CSS
Moderator
Moderator
Posts: 12711
Joined: Thu Mar 09, 2006 5:32 am
Location: Arizona

Re: making my *.tpl file look different if!

Post by Dr.CSS »

[solved]  ?...
Post Reply

Return to “Developers Discussion”