<!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">
<head>
<title>Smarty Test</title>
</head>
<body>
<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
Smarty is stressing me out
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:
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.
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.
hiigara,
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.
~ply
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.
~ply
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?
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?
remmargorp,
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
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:
<html> <head><title>Test</title></head> <body> {$entirePageHtml} </body></html>
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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement