Page 1 of 1
making my *.tpl file look different if!
Posted: Wed Oct 24, 2007 3:38 pm
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?
Re: making my *.tpl file look different if!
Posted: Wed Oct 24, 2007 3:51 pm
by calguy1000
tpl files are smarty templates, see
http://smarty.php.net/manual/en
Re: making my *.tpl file look different if!
Posted: Wed Oct 24, 2007 8:18 pm
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?
Re: making my *.tpl file look different if!
Posted: Wed Oct 24, 2007 8:50 pm
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.
Re: making my *.tpl file look different if!
Posted: Wed Oct 24, 2007 9:07 pm
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!
Re: making my *.tpl file look different if!
Posted: Wed Oct 24, 2007 9:15 pm
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']);
Re: making my *.tpl file look different if!
Posted: Fri Oct 26, 2007 8:28 am
by jmansa
Thanks alot... That was it!:-) I'm trying to create a module.
Re: making my *.tpl file look different if!
Posted: Sat Oct 27, 2007 2:44 pm
by Dr.CSS
[solved] ?...