Well I am trying to incorporate smarty as my template engine. It does not work out right, and instead it shows nothing but a blank page. But this is not really the problem, the issue is that I do not receive any warnings, errors or notices, nothing at all. I make sure the error reporting setting is set to E_ALL, it still wont show anything. Do anyone of you have experience working with Smarty? I heard that Smarty by default turns off error reporting, is there a way to enable it instead? Theres no way I can debug smarty when it shows just a blank page. Even some error messages can at least help me learn what the problem is... sigh
umm anyone knows how to debug smarty?
I have never used smarty, but my coworkers have. When the word is even whispered, they run for the hills. None of them have even one nice thing to say about it. Is it absolutely necessary to use in your project?
Well I think so, it gives me headache to see lots of PHP <? and ?> tags in html files, and smarty's templates make it look so much nicer. Perhaps its just me though.
That's just from a quick google search. I think I've mentioned my opinion of Smarty.
Lord Yggdrasill;11018751 wrote:smarty's templates make it look so much nicer. Perhaps its just me though.
You can avoid looking at all of that syntax altogether and just use something like Microsoft Frontpage to design your website!
bradgrafelman;11018755 wrote:You can avoid looking at all of that syntax altogether and just use something like Microsoft Frontpage to design your website!
I said it was just my personal opinion, its not like I am trying to force my idea on anyone of you. I dont like having different languages running on the same script, I separate php from html almost completely. If you do not like it, dont bother.
And after consulting with my host, they found that the inclusion of smarty class was blocked by suhosin. Its kinda weird, but it does explain lots of things such as var_dump() does not show anything after I call include() function on smarty class. I was wondering though, do anyone of you know what is a valid/allowed include path for suhosin? Right now I am using this in my script:
include("http://www.domain.com/scriptpath/inc/smarty/Smarty.class.php");
Is the www part the cause of the error? Or is it with the file name Smarty.class.php? In the worst case scenario I just copy/paste smarty class into the script calling it so it can be loaded, lol.
Is this on the same server as your site? If so, try using the path rather than a URL.
Lord Yggdrasill;11018765 wrote:Right now I am using this in my script:
include("http://www.domain.com/scriptpath/inc/smarty/Smarty.class.php");
That shouldn't do anything useful, since you'll only be include()'ing whatever is output by Smarty.class.php. So, unless that file is outputting a bunch of code (e.g. you could directly navigate to that URL in your web browser, view the source code of the page, and see the PHP code you expect to be include()'ing), using a URL here doesn't make any sense.
traq;11018769 wrote:Is this on the same server as your site? If so, try using the path rather than a URL.
Yeah it is, which is kinda strange.
Edit: I've found the cause of the problem. It seems that suhosin was blocking the include path, I have to use relative path instead of the path beginning with http://www to get it to work. But this introduces a problem though, it can be a headache when I have to decide how many '../' I have to use in the include path.
Lord Yggradsill wrote:It seems that suhosin was blocking the include path, I have to use relative path instead of the path beginning with http://www to get it to work.
That's not surprising. URLs are not file paths. Requesting a file to include via http is a potential security risk, since it implies that the server supplying the document is someone else's.
Weedpacket;11018781 wrote:That's not surprising. URLs are not file paths. Requesting a file to include via http is a potential security risk, since it implies that the server supplying the document is someone else's.
Yeah I figured, I am using the server var $_SERVER['DOCUMENT_ROOT'] in place of http://www.domain.com/, which works out nicely. There is still one more issue with smarty. When I have a variable that contains url to an external site assigned to smarty template, it will generate a blank page too. One example is this:
$credits = "Template Designed by <a href = 'http://www.templatedesign.com'> Smarty Template Design Inc</a>";
$smarty->assign("credits", $credits);
And in the .tpl file it gives a blank page if I attempt to use this variable {$credit}, the blank page goes away as long as I remove it. Is there a way to help with this?
Lord Yggdrasill wrote:I dont like having different languages running on the same script
I note that if you are using smarty within some HTML page, then technically you are mixing a template language with HTML, so you have "different languages running on the same script". If you use PHP as a template language, then you are still mixing a template language with HTML, so the real difference to you is that "smarty's templates make it look so much nicer"
Lord Yggdrasill;11018785 wrote:Yeah I figured, I am using the server var $_SERVER['DOCUMENT_ROOT'] in place of http://www.domain.com/, which works out nicely.
No, it doesn't work out nicely. Well, it may work under certain conditions, but they relate to two entirely different concepts, not just two different strings. These two on the other hand are two different strings, which both (possibly) represent file paths, (and possibly might be used as such)
$string_one = '/path1/file';
$string_one = '/path2/file';
[/code]
While these two are also two different strings - but not file paths They are in point of fact, URLs
$string_one = 'http://example.com/path1/file';
$string_one = 'http://example.com/path2/file';
Do note that accessing a file path means you HAVE to be on the same machine as the file, or otherwise be able to mount a remote disk locally. This is not done via HTTP, altough I supposed you could write code to do so. Also note that accessing an URL means you need to make a HTTP REQUEST to a WEB SERVER, which is completely different than accessing the local file system, even though both requests MAY end up accessing the same file on the same disk.
And finally note that /path1/file above MAY actually refer to the same file being accessed with http://example.com/path2/file, while /path2/file above MAY actually refer to the same file being accessed by http://example.com/path1/file (and no - there are no variables involved, just plain strings).
Lord Yggdrasill;11018785 wrote:There is still one more issue with smarty. When I have a variable that contains url to an external site assigned to smarty template, it will generate a blank page too.
Blank pages are caused by pages containing no output. Or serious errors. Or some additional stuff which performs post processing and fails miserably when there are errors.
Lord Yggdrasill;11018785 wrote:One example is this:
$credits = "Template Designed by <a href = 'http://www.templatedesign.com'> Smarty Template Design Inc</a>"; $smarty->assign("credits", $credits);
Well, if you consider the above a complete example, there is no output. Thus, if you get a blank page, it's working as expected. However, if you do output the above into a document served as HTML, ther will be errors.
I'm not certain about how HTML5 would treat "href", but I'm guessing it'd work like any other such construct, which would be equal to href="href", which in turn would take you to the RELATIVE PATH document "href". On the other hand, if I try that in Firefox, it takes me to the document root, so it could be href is allowed under HTML5, and defaults to document root (as in http://example.com/ and NOT as /path/to/docroot/). But I doubt it's actually valid HTML 5.
But I do know that there is no attribute named = and there certainly is no attribute named 'http://www.templatedesign.com'.
Try removing some white spaces and see what happens.
Lord Yggdrasill;11018785 wrote:And in the .tpl file it gives a blank page if I attempt to use this variable {$credit}, the blank page goes away as long as I remove it. Is there a way to help with this?
Smarty ought to ouput whatever you tell it to, as far as I know. But perhaps you have other things, or perhaps it's possible to set up smarty to do additional parsing, and that one or the other stops output when it encounter certain things that are invalid as HTML. But if you copy paste that link into an html page, and then run that page through a validator (http://validator.w3.org), you'd get those errors. Moreover, if you serve the page as XHTML, the href attribute most definitely has to have an explicit value (which possibly may be empty).
But as far as I know smarty, it would NOT care about invalid HTML output. Smarty is supposed to let you output whatever you like and doesn't concern itself with what that output is.
Since it seems the opinions of Smarty ranges from "really bad" to "simply useless since PHP was designed to do what smarty is doing to begin with", I have to pitch in my opinion and state that I like it. As for the second opinion, well... PHP was designed to do a few things, and yet there are today several libraries and frameworks, and you have probably written some things to abstract away basic functionality yourself. Why? Because it's more readable, reusable, etc. As for it being "really bad", well, I'm a bit curious as to how it's "really bad".
First off, I really like the caching. It's esay to have separate parts of a page being not cached at all, cached for some, cache for all, and cached for different amounts of time. Each language version cached separately (automatically in combinations of the above). Can I do the same thing using PHP? Of course. But it doesn't necessarily mean I'd want to. Or that I'd get it right if doing it from scratch every time... oh the horror.
Iteration is identical to PHP, but you will easily keep indented html and readable code, even with large blocks and nested loops
And in the thread referred to above, it was said that
$title = "Some page";
followed by
<title><?= $title; ?></title>
was better for a designer than anything else would be. Apart from definitely not agreeing that short open tags are good for anyone, I fail to see how it differs from
$smarty->assign('title', 'Some page');
<title>{$title}</title>
And since smarty 3, instead of assigning smarty-global variables, you can keep then template-local, so that $title may be page title in one template while it's a text heading in another.
Also while you may actively work around keeping logic and presentation separate when using smarty, it's pretty decently constructed for making that come naturally.
As for using Microsoft FrontPage, do such tools actually generate any kind of code you'd want to look at? I've never used them myself, so I wouldn't know. But having no real knowledge of what they do and don't... it's my opinion that they are far off from doing things directly - be that using php to generate html or using smarty to generate php that generates html.
johanafm;11020481 wrote:Apart from definitely not agreeing that short open tags are good for anyone
I fail to see how they are NOT good for anyone, in fact that's why <?= syntax is available by default in php5.4+ even when short open tags are disabled. Its a new day, and a new way. I definitely prefer to see <?=$var?> than <?php echo $var ?> I find it far more readable.
<?= is different from regular short tags though. I recently hit this problem where I wrote some code to output RSS feeds, and the whole thing choked at the XML declaration because short open tags meant it was expecting PHP. In the end I had to use PHP to echo the XML declaration; a minor annoyance, but still an annoyance just the same.
Ashley Sheridan;11020501 wrote:<?= is different from regular short tags though. I recently hit this problem where I wrote some code to output RSS feeds, and the whole thing choked at the XML declaration because short open tags meant it was expecting PHP. In the end I had to use PHP to echo the XML declaration; a minor annoyance, but still an annoyance just the same.
I've had to do that for what seems like EONS.
bradgrafelman wrote:You can avoid looking at all of that syntax altogether and just use something like Microsoft Frontpage to design your website!
Bwahahah! Wonderful!!!!!!! Can I get it from Pirate Bay or Depositfiles, or do I have to install Kazaa??
[FONT=Comic Sans MS]( +1 for your trolling today, Brad )[/FONT]