View previous topic :: View next topic |
Author |
Message |
edemocracyub Smarty n00b
Joined: 27 Feb 2004 Posts: 1
|
Posted: Fri Feb 27, 2004 6:40 pm Post subject: trying to learn to use Smarty. |
|
|
Hi ,
I'm trying to learn to use smarty...I have read all the documentation and few tutorials but I still don't get it.
btw. it would be really helpful if someone knows a web site where the use of smarty codes can be studied.
any help will be very helpful.
Thanks. |
|
Back to top |
|
Duncan Smarty Pro
Joined: 16 Dec 2003 Posts: 166
|
|
Back to top |
|
MindPhlash Smarty Rookie
Joined: 14 May 2008 Posts: 10
|
Posted: Thu May 15, 2008 5:51 pm Post subject: |
|
|
I bought the one book that I could find on it - Smarty - PHP Template programming and Applications, but it's still not the world's greatest reference.
I find myself doing a lot of {php} {/php} as hacks around just to make things work, but I know there's ways to do things in smarty because I see the tags for them, the tags just arn't explained / documented all that well
another thing I'd reccomend would be the smarty cheat sheet http://hasin.wordpress.com/2006/06/10/smarty-cheat-sheet-version-20/
(it's from one of the guys that wrote the smarty book), and I keep it at my desk with my favorite CSS cheat sheet |
|
Back to top |
|
shannera Administrator
Joined: 13 Feb 2006 Posts: 802 Location: Edertal, Germany
|
Posted: Fri May 16, 2008 12:07 am Post subject: |
|
|
If you have to use {php} tags, you are surely making something wrong. I'm using Smarty for a few years, and hadn't used any php tags, because anything that can be placed in PHP tags can also be placed in the calling script.
Also I don't understand that you find the documentation isn't good enough. What tags are you referring to? |
|
Back to top |
|
MindPhlash Smarty Rookie
Joined: 14 May 2008 Posts: 10
|
Posted: Fri May 16, 2008 12:28 pm Post subject: |
|
|
On of the tags I've been finding lacking on documentation is the $smarty.session reserved variable
I'm using sessions in my current site, however I've tried a few times to use the reserve $smarty tag but I could never seem to get the exact way on how it worked even after reading http://www.smarty.net/manual/en/language.variables.smarty.php
so instead I've been using a piece of code such as :
Code: | {php}
session_start();
//echo $_SESSION["logged_in"];
if(!session_is_registered(myusername)){
header("location:index.php");
}
{/php}
{include file='header.tpl'} |
if you could give me a pointer on how to make this more efficient then I'm more then willing to listen and learn.
After all I'm about to add more things to my sessions then just checking to see if the username is registered |
|
Back to top |
|
Celeb Administrator
Joined: 17 Apr 2007 Posts: 1025 Location: Vienna
|
Posted: Fri May 16, 2008 1:01 pm Post subject: |
|
|
$smarty.session is nothing but a "name" for the $_SESSION superglobal array.
You can do stuff like
Code: | {if isset($smarty.session.username)}
Hello {$smarty.session.username|capitalize}!
{/if} |
Maybe we could help you further, if you'd post a piece of code that doesn't work correctly for you.
Btw, I'd do all the session handling, authentication, etc in PHP rather than in the template and only set some flags to let Smarty know which parts of the website you want to be displayed. _________________ Darn computers always do what I tell them to instead of what I want them to do. |
|
Back to top |
|
MindPhlash Smarty Rookie
Joined: 14 May 2008 Posts: 10
|
Posted: Fri May 16, 2008 1:33 pm Post subject: |
|
|
I just tried the {if} statement that you gave me for the smarty sessions, but nothing showed up
here's where I declared my session variables upon login:
Code: |
session_register("myusername");
session_register("mypassword");
$_SESSION['views'] = $_SESSION['views'] + 1; // store session data |
then here's where I took the code you gave me and thought I changed the variable right to display the username???
Code: | {if isset($smarty.session.myusername)}
Hello {$smarty.session.myusername|capitalize}!
{/if} |
(now this page still does have my origional {PHP} session codeblock at the top to check and make sure that the user is logged in) - not sure if that is effecting anything |
|
Back to top |
|
Celeb Administrator
Joined: 17 Apr 2007 Posts: 1025 Location: Vienna
|
Posted: Fri May 16, 2008 1:52 pm Post subject: |
|
|
The use of session_register() is deprecated.
Why don't you do it like this:
Code: | session_start();
$_SESSION['myusername'] = 'bob';
$_SESSION['mypassword'] = 'hidden';
$_SESSION['views']++; |
You can also print_r($_SESSION) to see which variables are set at all. _________________ Darn computers always do what I tell them to instead of what I want them to do. |
|
Back to top |
|
LynnGillam Smarty n00b
Joined: 21 Dec 2015 Posts: 1
|
Posted: Fri Jan 01, 2016 12:51 pm Post subject: Tutorial Website |
|
|
I have searched the web for the coding tutorial, the website come front which i thought that may helping you is : http://www.tutorialspoint.com/computer_programming/. I hope it may be helpful to you. |
|
Back to top |
|
|