View Single Post
  #1  
Old 07-15-2014, 04:33 PM
Kyttias's Avatar
Kyttias Kyttias is offline
Premium Member
 
Join Date: Jan 2014
Posts: 857
Gender: Unknown/Other
Credits: 91,141
Kyttias is on a distinguished road
Arrow Smarty Tips: Things you can do with Templates

Mysidia is built with the Smarty template system. Here's some fun facts:

You can write multiple conditions using the {if} {elseif} {elseif} {else} {/if} style. In Smarty, you can also implement a nested {if} {/if} block.

You can display the current date in your template with {$smarty.now|date_format} and it will print in the format Jul 15, 2014. For the time, check out {$smarty.now|date_format:"%H:%M"} for military time that prints 16:45, or {$smarty.now|date_format:"%I:%M %p"} for 04:45 PM. If you know how php prints dates, you can probably figure out how to customize this a ton!

For fun, pop open classes/class_template.php and inside private function assignTemplateVars(){ after it's row of this->s are done, add these:

PHP Code:
$mysidia Registry::get("mysidia");
$this->assign("logged_in",$mysidia->user->isloggedin);
$this->assign("username",$mysidia->user->username); 
$this->assign("cash",$mysidia->user->getcash());
$messages $mysidia->db->select("messages", array(), "touser='{$mysidia->user->username}' and status='unread'")->rowCount(); 
$this->assign("messages",$messages); 
This has assigned four variables to Smarty.

In your template.tpl, you can now do this:

Code:
{if $logged_in} 
<a href="{$home}profile/view/{$mysidia->user->username}">{$username}</a>		
${$cash} {$mysidia->settings->cost}
<a href="{$home}messages">{$messages} Messages</a>
<a href="{$home}login/logout">Log Out</a>
{else}
Please <a href="{$home}login/logout">Log In</a> or <a href="{$home}register">Sign Up</a>!
{/if}
The above will:
- only display if a user is logged in
- print their username, which will link to their profile
- show how much currency they have and the name of your currency
- show how many messages they have, and a link to go check them out
- show a log out link when they are logged in
- when they aren't logged in, it will ask them to log in or sign up

You'll definitely want to work around this and make it pretty. ^_~

Another example might be a message that shows up 30% of the time:
Code:
{if rand(0,100) <= 30} Winner! {/if}
__________________
Please do not contact me directly outside of Mysidia.
I also cannot troubleshoot code more than two years old - I legit don't remember it.

Last edited by Kyttias; 04-03-2015 at 10:01 AM.
Reply With Quote