Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Advantageous to switch to smarty?

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
frost
Smarty Rookie


Joined: 29 Apr 2003
Posts: 13
Location: Canada eh?

PostPosted: Tue Apr 29, 2003 4:50 am    Post subject: Advantageous to switch to smarty? Reply with quote

Hi there,

Firstly I would like to say that I am new to Smarty but very eager to get my hands dirty Smile

What I wanted to know is if using Smarty in my case would be advantageous. My current setup involves a header and a footer file; inside each are various functions (to keep things neat) which take a variable ($language) to output things like graphics and the nav bar in the proper language. Then for each page there is separate PHP file which pulls the header and footer, check the $language and outputs the proper text. I have done this so I can edit the pages in Dreamweaver relatively easily.

If I were to switch to Smarty, would I have to redo all my functions? Could I perhaps keep my PHP (using {php}) or would this not be efficient?

I have read the other post about multiple language sites and have to say I was rather intimidated. I'm guessing that the methods mentioned there would be optimal when compared to mine. My main goal is to be able to work with something that is easy to manage/update and is hopefully fast as well.

Any thoughts or ideas would be greatly appreciated.

Best regards.
_________________
w00t Smile
Back to top
View user's profile Send private message
andre
Smarty Pro


Joined: 23 Apr 2003
Posts: 164
Location: Karlsruhe, Germany

PostPosted: Tue Apr 29, 2003 7:25 am    Post subject: Reply with quote

Sounds you could use Smarty easily. But what you have now is no real Template engine, isn't it? So using Smarty would be only a advantage if you make use of the Smarty functions.

A example what you could do with Smarty
Code:

  {* Header Template *}

  {if $language == "en"}
     <img src="flag_us.gif">
  {elseif $language == "de"}
     <img src="flag_de.gif">
  {else}
     ...
  {/if}

  {* include navigation menu for specific language *}
  {include file="navigationMenu_`$language`.tpl"}


Code:

  {* Footer Template *}
  (c) 2003 by Example Inc.


Code:

  {* Main Template *}
  {include file="header.tpl"}
   
  {* This is my content *}
  foo bar

  {include file="footer.tpl"}


Quote:
If I were to switch to Smarty, would I have to redo all my functions? Could I perhaps keep my PHP (using {php}) or would this not be efficient?


Sure you can use {php} what doesn't slow down your templates. It makes them just harder to read and it's more unsafe. But in first step you can do it this way and remove the {php} tags step by step.
Back to top
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Tue Apr 29, 2003 8:08 am    Post subject: Reply with quote

Quote:
Sure you can use {php} what doesn't slow down your templates. It makes them just harder to read and it's more unsafe. But in first step you can do it this way and remove the {php} tags step by step.


The key to remember is that you can do all of your PHP code BEFORE you call $smarty->display() to output your template. In fact, this is one of Smarty's strengths: separating your application logic from your template design (and internal template logic).

Try replacing a very small portion of your site with Smarty and see what you think. You are likely going to have to re-think certain elements of your design but if your code organized well, moving to Smarty should be fairly straightforward.

Depending on how you (ab)use it, Smarty can slow your site down or tremendously improve its performance. Its built-in cache is an excellent feature. Its ability to have multiple compiled versions of a template lets you do things like keep a separate compilation for each language you support (meaning more speed).

There is a lot to Smarty which can be intimidating. Smarty is modular and lets you use just the features you want. Take it one step at a time and start simply and small. When you are comfortable, try out some of the more advanced features. They are well worth it!

Do read the manual--it has plenty of good information and examples, answers to many often asked questions and is an all-round commendable work. The wiki also has some good references and my experience is that the folks on this forum are very friendly.

Good luck!
Back to top
View user's profile Send private message
frost
Smarty Rookie


Joined: 29 Apr 2003
Posts: 13
Location: Canada eh?

PostPosted: Thu May 01, 2003 3:44 am    Post subject: Reply with quote

Thank you andre and boots for your very helpfull suggestions!

Smarty is definatly a journy which I wish to embark on Smile

From what I understand from your comment boots is that I could keep all my php code and then assign the proper values to my templates to display the correct language.

May I ask which the preferred method is and if either has an advantage over the other. From what I understand these would be the two methods.

In the template file
Code:

{if $language == "en"}
<img src="flag_us.gif">
{elseif $language == "de"}
<img src="flag_de.gif">
{else}


On the page itself
Code:

if $language == "en"
$smarty->assign('flag', 'flag_us.gif');
elseif $language == "de"
$smarty->assign('flag', 'flag_de.gif');


The advantage I currently see is that with the first method I would not need to worry about having the same code at the top of every page or worry about it getting messed up. This could easily be solved by using an include file however. I would still be very interested to see the opinions of those who have some experience with Smarty.

Also another quick question. What would be the best way to include the actual contents of the page. The way I have it setup right now is that all the content is on one page, that way if i edit one language file I can edit the other at the same time without having to find the corresponding file.

Again thanks for all the help!
_________________
w00t Smile
Back to top
View user's profile Send private message
Wom.bat
Smarty Pro


Joined: 24 Apr 2003
Posts: 107
Location: Munich, Germany

PostPosted: Thu May 01, 2003 12:26 pm    Post subject: Reply with quote

do it in the template, frost... maybe you want to display the language name one day instead of displaying the flag or the flag names change or whatever... things like these NEVER belong into PHP code, this is presentation logic
Back to top
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Thu May 01, 2003 1:19 pm    Post subject: Reply with quote

Wom.bat wrote:
things like these NEVER belong into PHP code, this is presentation logic


I don't know... Doesn't the designer just want to layout where the flag goes without caring which particular flag is put there ??
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP