#1
|
||||
|
||||
Smarty and Conditional Templating~?
So I've been reading through Smarty documentation, since Mysidia is built using that templating system.
The documentation suggests we can do things such as the following in our template (.tpl) files: PHP Code:
My complaint with the sidebar usage is that... well... I want more freedom than that? I want to place it in anywhere in my template (.tpl) and not have to mess with deep Mysidia files every time I want to place my user's name or currency amount. If I want to display any variable on this site, I want to make full use of the Smarty templating. I think some considerations for the next version of Mysidia should be made in regards to variables accessible to us from any page, any where, any time. In short - Where can I/should I/do I position Registry::get("mysidia"); to make its usage global? How do I go about shortening {$mysidia->user->username} to {$username}, {$mysidia->user->isloggedin} to {$logged_in}, and {$mysidia->user->money} {$mysidia->settings->cost} to {$currency}? ~ <3 Last edited by Kyttias; 06-17-2014 at 03:26 PM. |
#2
|
||||
|
||||
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:
PHP Code:
PHP Code:
-------------- To assign the loggedin variable to a Smarty variable called logged_in in class_template.php: PHP Code:
More examples (in class_template.php): PHP Code:
__________________
asp.net stole my soul. |
#3
|
||||
|
||||
I've still yet to get it to work completely.
Let's start with what I've successfully done - In class_template.php's assignTemplateVars() function I've added: Code:
$mysidia = Registry::get("mysidia"); $this->assign("logged_in",$mysidia->user->isloggedin); $this->assign("username",$mysidia->user->username); $this->assign("cash",$mysidia->user->getcash()); $this->assign("currency",$mysidia->settings->cost); Code:
{if $logged_in} Welcome, <a href="{$home}profile/view/{$username}"><b>{$username}</b></a>! <br/> You have {$cash} <b>{$currency}</b>. {else} Please sign up or log in~! {/if} However, using - Code:
$this->assign("group",$mysidia->user->getusergroup()); I'm as of yet unsure how or if the messages work, but I'd like it to just display a number of unread messages a user has, and possibly 0 if there is none? I have no messages, so nothing appears. It looked like it would display more than just a number, but information about the messages. I don't think I need that, but a number next to an envelope icon is floating in my head as a pleasant sight. Also, thank you very much! Last edited by Kyttias; 11-05-2014 at 02:11 PM. |
#4
|
||||
|
||||
Sorry! It's $mysidia->user->getgroup()! Which will return one of the groups available in your database (rootadmins, admins,registered,artists,banned,visitors).
Messages is an array containing multiple message objects, that's why I use foreach there, it goes through every "item" in the messages variable. Each Message contains a title, content, date, etc... To get just the number of new messages: $messages = $mysidia->db->select("messages", array(), "touser='{$mysidia->user->username}' and status='unread'")->rowCount(); $this->assign("messages",$messages);
__________________
asp.net stole my soul. |
#5
|
||||
|
||||
Awesome! Very soon I'll have replaced the entire sidebar. Added this, too:
Code:
$online = $mysidia->db->select("online", array(), "username != 'Visitor'")->rowCount(); $offline = $mysidia->db->select("online", array(), "username = 'Visitor'")->rowCount(); $this->assign("population","{$online} Users Online, {$offline} Guests"); Code:
<a href="{$home}/online">{$population}</a> Code:
$now = new DateTime(); $display = $now->format('h:i A'); $this->assign("time",$display); Also~!! I almost forgot Mysidia had a friend's list system. The 'send friend request' button is currently on the last tab of the profile... I'll be moving that to the front where it's easier to find. However, Is there a table in the database that may be able to help me make a notification system for unaccepted/new friend requests? And I seem to be overlooking where I can link users to a list of their own friends, other than their profile... Last edited by Kyttias; 06-17-2014 at 06:37 PM. |
#6
|
||||
|
||||
Hehe it's good you are getting used to it ^^ The table friend_requests might help, status = pending means unaccepted.
The table users keeps a list of friends as a string (each friend separated by a comma). The way profile does it is to create a Friendlist object (class_friendlist), with the user object. The Friendlist object then creates an array of integers (the friends IDs) by dividing the entire string (explode(",",string)). I'd look into class_userprofile.php (getfriends() function) and class_friendlist.php depending on what you want to do. mysidia->user->getfriends() seems to return the full string with friends as well, if you want to use Explode() on it yourself. After Explode() you get an array with all the ids, you can then create a Member object using those ids.
__________________
asp.net stole my soul. |
#7
|
||||
|
||||
Ah, what if I just wanted the number of pending friend requests, but not a list of names? Is that simpler? (Is exploding supposed to sound dangerous, because it does.) I'll take a closer look in a few minutes, but I really can't thank you enough for all this help. ovo~
I could probably make a tooltip with a fun combination of Smarty conditionals and Javascript, that if the 'pending requests' are 'greater than 0', hovering over the notification would pull down a notification with, if I knew how to get this information, the pending friend(s) names and links to confirm or deny them without the need to travel to a new page. But that sounds more ambitious than I want to trouble myself with for tonight. On a similar vein, if the messages in the inbox were 'greater than zero', to hover over the number and show some basic information, like the message titles (wherein clicking a specific title would take you to that specific message as well) and the senders, of about the first three messages, sort of like you had originally given. I'll probably accumulate the things I've learned here into a nice convenient post for others eventually. My intention is, of course, to give people a way to easily install something like this, to go under a header image of their choosing: Last edited by Kyttias; 06-17-2014 at 08:39 PM. |
#8
|
||||
|
||||
You wouldn't mind making a mod for this and putting it in the mod section, would you please? I like your changes and I'd love to have something similar for my site. I don't want to copy you, but something simple like showing how much cash you have on each page, unread messages, etc, those are must haves.
|
#9
|
||||
|
||||
Quote:
Last edited by Kyttias; 06-18-2014 at 02:16 AM. |
#10
|
||||
|
||||
It should be very easy to make a friend request notification system. The mechanism can be very similar to new PM notification, my suggestion is to look at how PM notification is generated and make something similar to this. In fact, this feature is planned for Mys v1.4.0.
__________________
Mysidia Adoptables, a free and ever-improving script for aspiring adoptables/pets site. |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Smarty Tips: Things you can do with Templates | Kyttias | Tutorials and Tips | 5 | 04-03-2015 10:53 AM |
Assigning array to smarty variables | IntoRain | Questions and Supports | 3 | 06-03-2014 02:06 PM |
Smarty errors and WAMPP | Kesstryl | Questions and Supports | 15 | 01-29-2014 09:07 PM |
Problem: smarty class 1.3.4 | draugluin | Questions and Supports | 8 | 11-15-2013 02:29 AM |
What's New? |
What's Hot? |
What's Popular? |