View Single Post
  #2  
Old 06-17-2014, 04:10 PM
IntoRain's Avatar
IntoRain IntoRain is offline
Moderator
 
Join Date: Jul 2013
Location: Portugal
Posts: 461
Gender: Female
Credits: 19,565
IntoRain is on a distinguished road
Default

I'm currently enjoying the joys of Smarty, after having to use it for a class this semester. I will see if I can explain this well! :D

Basically Smarty is a way to code a template without putting PHP and HTML together. You basically need to assign a PHP variable into a Smarty variable, to be able to use it in a .tpl

I usually set my variables in class_template.php's assignTemplateVars() function with

PHP Code:
$this->assign("nameToUseInTemplate",$nameOfVariable); 
and in class_frame.php with

PHP Code:
$mysidia->template->assign("temp",$var); 
So, in those files, as long as you have this:

PHP Code:
$mysidia Registry::get("mysidia"); 
You can use anything from mysidia.

--------------

To assign the loggedin variable to a Smarty variable called logged_in in class_template.php:

PHP Code:
$mysidia Registry::get("mysidia");
$this->assign("logged_in",$mysidia->user->isloggedin); 
You can now use {$logged_in} in your template.tpl file.

More examples (in class_template.php):

PHP Code:
$mysidia Registry::get("mysidia");
$this->assign("logged_in",$mysidia->user->isloggedin);

//get user's cash
$this->assign("user_cash",$mysidia->user->getcash());

//get user's username
$this->assign("username",$mysidia->user->username);

//get user's group
$this->assign("group",$mysidia->user->getusergroup());

//get user's new unread messages (3 max)
$messages $mysidia->db->select("messages", array(), "touser='{$mysidia->user->username}' and status='unread' ORDER BY id DESC LIMIT 3")->fetchAll();
$this->assign("messages",$messages);

//using messages in template.tpl (example):
{foreach from=$messages item=message}
<
a href="/messages/read/{$message.id}">
      
From:{$message.fromuser}
      
Title:{$message.messagetitle}
      
Date:{$message.datesent}
</
a>
{/foreach} 
__________________


asp.net stole my soul.
Reply With Quote