Jump to content
  • Advertisement
Sign in to follow this  

Smarty is stressing me out

This topic is 3122 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm brand new to Smarty and have poured through all their entry level docs, but for the life of me I can't seem to find the solution to what I'm looking for. I'm designing a PHP web-based gaming application. Each page page has the same basic template: (1) Vertical menu system on the left border of the page; this is the same for every page (2) Special top section (bordering the page top) that outputs the result of some complicated PHP functions; different for every page (3) Page content section (to the right of the vertical menus and below the top section); this will house each page's custom content and will be different for each page (4) Page footer along page bottom border; same for every page So, of the 4 sections, only two sections can really be thought of as "static" (their content won't change regardless of what page you're on: the menu, and the footer. Smarty works by defining a PHP page ("Sample.php") and using it to define a Smarty object, assign values to Smarty variables, and to then compile (display) the Smarty object's output (cookie-cutter-customized HTML). You then define a template file (.tpl) that Smarty's compiler will use to cut-n-paste your custom data. So here was my first attempt:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
            <title>Smarty Test</title>
		<div id="#menus">

<div id="#top-section"> {$topSectionHtml}
<div id="#page-content"> {$pageContent}
<div id="#footer">
</body> </html> [Edit]: The HTML above is correct but the forum software is stripping tag brackets out. The problem (that I realized almost immediately) is that $topSectionHtml, and especially $pageContent, are *humongous* blocks of PHP-derived HTML. How can I set up my template and PHP files to accomplish using the above template, but so that $topSectionHtml and $pageContent are customized for every page? Thanks for all ideas/suggestions, ~plywood

Share this post

Link to post
Share on other sites
I personally hate Template Systems, it's like having to learn another Language on top of PHP, which is itself a Template language.
I never used them, and if you google you will find, that I am not the only one who refuses to use them.
For example, my favorite Forum Script is punbb. Because the php files are themselves the Template. It's easy to find which PHP file outputs what. And easy to make changes and integrate in any other Login system in a matter of 5 minutes. Sorry for the Rant.

Share this post

Link to post
Share on other sites

I appreciate the response and advice, but I'm having a tough time accepting it! If my web app has 1300 PHP files/pages, and they all use a lot of the same code, and then I decide I want to change that code, without a templating system I have to propagate the changes 1300 times!

If anyone knows something different, please speak up! Also, there's nothing *marrying* me to Smarty. If there are better template engines for PHP I'd love to hear some suggestions.


Share this post

Link to post
Share on other sites
Am I reading into your original post correctly...

You are able to define the template, however you are having a problem populating the variables $topSectionHtml and $pageContent due to the amount of data you need to save into each variable?

If yes...

Are you *sure* you are hitting a limit with-in PHP?
What is the memory limit configuration for PHP? If small (<16MB) I would suggest increasing to a more reasonable amount for your application

16MB (the default setting in 5.2.0 and later) is a *LOT* of HTML content, are you really trying to store 16MB of HTML data into a variable?

Share this post

Link to post
Share on other sites

For some reason this is going to be very hard for me to explain...

In fact after writing several paragraphs, only to delete them and start over again, now some 4 or 5 times, I'm just going to pose a question, whose answer should clear things up.

Two web pages: Foo.php and Bar.php. Each uses the following template:


Both pages have very different content. Do you see that I can't use just a simple variable... it would take so long and require so much effort to smarty->assign() each pages HTML into $entirePageHtml...

Also, this is an extreme example, as in such a case one would probably use different templates since each page was so different from one another. In my case, about 75% of each page will use the same template-able content, but the 25% that isn't is too huge to store in one little lousy variable.

I also recognize that maybe I just don't get the "Smarty philosophy" and maybe my approach is dead wrong.

Thanks for any ideas

Share this post

Link to post
Share on other sites
Sign in to follow this  


Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!