View previous topic :: View next topic |
Author |
Message |
pnoeric Smarty Rookie
Joined: 03 Mar 2006 Posts: 29
|
Posted: Tue May 01, 2012 12:01 am Post subject: Moving from Smarty 2-- how do have {dynamic} blocks? |
|
|
Hi, 2 small questions:
1. I have a pretty big web app that I'm moving from Smarty v2 to v3. I'm using the code from here to have a {dynamic} block:
Code: |
function smarty_block_dynamic($param, $content, &$smarty) {
return $content;
}
$smarty->register_block('dynamic', 'smarty_block_dynamic', false);
|
I see register_block doesn't work anymore in v3. I've been trying to sort out what my best options are here but I'm a little confused In Smarty v3, how I can indicate parts of my template that should always by dynamic (i.e. always parsed live, regardless of cache status)? Do I still need to wrap them in a {dynamic} block? If so, how I can set up for a {dynamic} block? Or is the new {nocache} block exactly the same functionality and I just need to change all my tags from "{dynamic}" to "{nocache}"?
2. I'm getting a weird compiler error. Here's my code:
Code: |
© 2008-{$smarty.now|date_format:'%Y'} My Company
|
And the error:
Quote: |
Fatal error:
Uncaught exception 'SmartyCompilerException' with message
'Syntax Error in template "/x/templates/nav.footer.tpl" on line 119
"© 2008-{$smarty.now|date_format:'%Y'} My Company" -
Unexpected "'}) © 2008-{$smarty.now|date_format:'",
expected one of: "}" , " "' in
/x/sysplugins/smarty_internal_templatecompilerbase.php:627
|
When I change the single quotes to double quotes (i.e. "%Y"), it complies just fine. Does Smarty v3 not allow single quotes in this case?! That seems like a very strange change. But I'm ok with it... just need to do a lot of code changes if so... (I couldn't find anything in the docs about this.)
THANK YOU--
best
Eric |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Tue May 01, 2012 7:22 am Post subject: |
|
|
1.
The API of Smarty3 has been changed in some places.
register_block($block, $block_impl, $cacheable, $cache_attrs)
has been replaced by
registerPlugin('block', $block, $block_impl, $cacheable, $cache_attrs)
See http://www.smarty.net/docs/en/api.register.plugin.tpl
But for dynamic content Smarty3 has also the new build in {nocache} ... {/nocache} tags.
2.
Code: | © 2008-{$smarty.now|date_format:'%Y'} My Company
|
does compile correctly.
To which version of Smarty3 did you upgrade? |
|
Back to top |
|
pnoeric Smarty Rookie
Joined: 03 Mar 2006 Posts: 29
|
Posted: Sun May 27, 2012 6:05 am Post subject: |
|
|
Thank you for the reply... sorry about the delay in getting back, but now I am here and really want to get my site moved up to Smarty3
I am trying to upgrade to Smarty v3.1.8.
Here is the exact error I am getting-- I have broken it onto several newlines to make it easier to read:
Quote: | Fatal error: Uncaught exception 'SmartyCompilerException'
with message 'Syntax Error in template "/Applications/XAMPP/xamppfiles/htdocs/fw/httpdocs/../templates/nav.footer.tpl"
on line 130
"You should sign up, or you'll miss new book lists!"
- Unexpected "'}) © 2008-{$smarty.now|date_format:"%Y"} Flashlight Worthy </span> <a href="/about.php?footer=1" rel="nofollow">About Us</a> <a href="/contribute.php" rel="nofollow">Contribute Your List</a> <a href="/forbloggers.php">For Bloggers</a> <a href="/contact.php">Contact Us</a> <a href="/terms.php">Terms of Service</a> </div> {* "add yourself to our mailing list" popup layer *} {nocache} {if $showemailsignup} <div id="emailpopup" style="display: none;"> <div id="emailpopup_main" style="display: block;"> <h3> You should sign up, or you'",
expected one of: "}" , " "'
in /Applications/XAMPP/xamppfiles/htdocs/fw/lib/smarty_v3/sysplugins/smarty_int
in /Applications/XAMPP/xamppfiles/htdocs/fw/lib/smarty_v3/sysplugins/smarty_internal_templatecompilerbase.php
on line 627
|
And here is the block of code around where it is complaining:
Code: |
<div id="footer">
<span class="dim">
({$smarty.now|date_format:'%D %R'})
© 2008-{$smarty.now|date_format:"%Y"} Flashlight Worthy
</span>
<a href="/about.php?footer=1" rel="nofollow">About Us</a>
<a href="/contribute.php" rel="nofollow">Contribute Your List</a>
<a href="/forbloggers.php">For Bloggers</a>
<a href="/contact.php">Contact Us</a>
<a href="/terms.php">Terms of Service</a>
</div>
{* "add yourself to our mailing list" popup layer *}
{nocache}
{if $showemailsignup}
<div id="emailpopup" style="display: none;">
<div id="emailpopup_main" style="display: block;">
<h3>
You should sign up, or you'll miss new book lists!
</h3>
(...etc, the code goes on from here)
|
And to be 100% clear, this code all works perfectly under Smarty 2.6.20.
Note that the error message seems to be malformed, too-- it references "sysplugins/smarty_int" which doesn't exist... it almost appears as if the compiler is running once, generating an error, and then somehow that error is being fed back into the computer and generating the 2nd error!
What do you think?
thank you--
Eric |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Sun May 27, 2012 8:40 am Post subject: |
|
|
The code section you have posted does compile correctly in my place.
Could you PM me the complete template file? |
|
Back to top |
|
pnoeric Smarty Rookie
Joined: 03 Mar 2006 Posts: 29
|
Posted: Sun May 27, 2012 7:00 pm Post subject: |
|
|
I found the problem-- about 10 lines above the code I posted, I had this:
Code: | {include file='nav.box.kindle.tpl}
|
As you can see, I was missing the trailing single quote.
Soooo... this was definitely User Error but maybe there is also an improvement for Smarty, to detect template mistakes like this and give a clearer error message. Should I file a bug report?
thank you--
E |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Sun May 27, 2012 7:29 pm Post subject: |
|
|
It's hard for smarty to guess where a single quote string should end.... |
|
Back to top |
|
pnoeric Smarty Rookie
Joined: 03 Mar 2006 Posts: 29
|
Posted: Sun May 27, 2012 7:36 pm Post subject: |
|
|
U.Tews wrote: | It's hard for smarty to guess where a single quote string should end.... |
I understand, though I wonder if the parser could be smart enough to recognize it's parsing a filename for an "include", so any newlines should invalidate the results? Anyhow, just a thought.
I'm VERY happy to report that after a few more tweaks to my code (like changing clear_cache() to clearCache(), that sort of thing), the site is working well under Smarty 3! Thank you very much. |
|
Back to top |
|
|