Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.
Smarty 3 beta 5 released
Goto page 1, 2, 3  Next
 
Post new topic   Reply to topic    Smarty Forum Index -> Smarty 3
View previous topic :: View next topic  
Author Message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7267
Location: Lincoln Nebraska, USA

PostPosted: Mon Nov 23, 2009 4:14 pm    Post subject: Smarty 3 beta 5 released Reply with quote

The fifth beta of Smarty 3 has been released! Please join the developer mailing list and see the Smarty 3 section of the forums and give us feedback!

http://www.smarty.net/
Back to top
View user's profile Send private message Visit poster's website
httpete
Smarty Rookie


Joined: 05 Dec 2009
Posts: 27

PostPosted: Sat Dec 05, 2009 1:58 am    Post subject: Works great Reply with quote

We have a large app with tons of investment in smarty 2. I just replaced it with Smarty 3 in about an hour. It is really peppy and the backwards compat work with smarty 2 is awesome. The only things I had to do were:

1.) Remove all calls to s_math ( a compiler plugin), change those to {math}
2.) some variables in the math calls needed an |intval in order to fly. Seems I was handing in a string before , and it needed an integer.
3.) The backtick syntax, which was ok in smarty 2 is no good. It was ugly anyway, and is much more straightforward with the {$var} in attributesl. so this:

{assign var="foo" value=`$whatver`-plainstring" }

is now

{assign var="foo" value="{whatever}-plainstring"}
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7267
Location: Lincoln Nebraska, USA

PostPosted: Sat Dec 05, 2009 2:05 am    Post subject: Reply with quote

hmm backticks should work ok
Back to top
View user's profile Send private message Visit poster's website
httpete
Smarty Rookie


Joined: 05 Dec 2009
Posts: 27

PostPosted: Sat Dec 05, 2009 2:41 am    Post subject: Found a potential bug Reply with quote

This is not working on smarty 3:


so I have a {foreach name="cols_to_display" }

and
{$smarty.foreach.cols_to_display.total} used to work , echoing the count.. I see in the readme:

$var@total foreach $var array total

but shouldnt the old syntax still work? This will really be hard for me, we have hundreds of foreach loops.
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7267
Location: Lincoln Nebraska, USA

PostPosted: Sat Dec 05, 2009 2:46 am    Post subject: Reply with quote

yes it should work, we'll take a look
Back to top
View user's profile Send private message Visit poster's website
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 4631
Location: Hamburg / Germany

PostPosted: Sun Dec 06, 2009 1:16 pm    Post subject: Reply with quote

Backtick syntax is still working.

In your example you had a missing double quote:

{assign var="foo" value="`$whatver`-plainstring"}


{$smarty.foreach.cols_to_display.total} syntax does work.
All of the special Smarty variables $smarty.foreach... nad $smarty.section... are still available.

Also you could get rid of all {math} tags. In SMarty 3 you can do math in any place directly.

Examples:
{$foo+$bar} will output the sum of $ foo and $bar
{counter start=$foo+$bar}
etc.
Back to top
View user's profile Send private message
httpete
Smarty Rookie


Joined: 05 Dec 2009
Posts: 27

PostPosted: Mon Dec 07, 2009 2:07 am    Post subject: Not working for me Reply with quote

So everything worked great, then I went to Smarty 3, and these errors got thrown and the only way I could fix was to remove the backticks on the include line below.

Code:

{assign var="include_filename" value="`$plugin_dir`submit-`$smarty.get.tpl`.tpl"}
{include file=`$include_filename`}


gives error: Syntax Error in template "/home/smith/GenomeQuest/trunk/src/web/system_plugins/Workflows/GqWfChipseq/submit.tpl" on line 31 "{include file=`$include_filename`}" - Unexpected "`", expected one of: "{" , "identifier" , "$" , "closing tag" , INTEGER , "+" , "-" , "(" , TYPECAST , "boolean" , "null" , SINGLEQUOTESTRING , """ , "#" , "["

The smarty.foreach.foreachloopname.total variable is empty in mine. Used to work fine.
Oh another clue - the smarty.foreach.foreachloopname.total is inside ANOTHER included template would that matter?

Code:

    {foreach from=$columns_to_display item=cell name="cols_to_display"}

{include file="anotherfilethattriesToEchoDotTotal"}

{/foreach}
[/code]
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7267
Location: Lincoln Nebraska, USA

PostPosted: Mon Dec 07, 2009 2:53 am    Post subject: Reply with quote

This isn't valid:

{include file=`$include_filename`}

Not even in Smarty 2. Needs to be:

{include file=$include_filename}
Back to top
View user's profile Send private message Visit poster's website
jakweb
Smarty n00b


Joined: 07 Dec 2009
Posts: 1

PostPosted: Mon Dec 07, 2009 9:38 am    Post subject: Reply with quote

Looking forward to try smarty 3, keep going guys...
Back to top
View user's profile Send private message
httpete
Smarty Rookie


Joined: 05 Dec 2009
Posts: 27

PostPosted: Mon Dec 07, 2009 1:30 pm    Post subject: Reply with quote

so that used to work in smarty 2 with no error, but that is ok since it is easy to fix. Its the .total issue which is my biggest one now. It is clearly not echoing inside included files within the foreach loop.
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 4631
Location: Hamburg / Germany

PostPosted: Mon Dec 07, 2009 3:47 pm    Post subject: Reply with quote

In Smarty 2 the special Smarty variables $smarty.section... and $smarty.foreach... had global scope. If you had loops with same name in subtemplates you could accidentally overwrite values of parent template.

In Smarty 3 these special Smarty variable have only local scope in the template which is defining the loop. If you need their value in a subtemplate you have to pass them as parameter.

Code:

{include file='foo.tpl' total=$smarty.foreach.cols_to_display.total}


Recently the SVN was extended by a file SMARTY2_BC_NOTES. It does contain a description of all know backward incompatibilities.
Back to top
View user's profile Send private message
httpete
Smarty Rookie


Joined: 05 Dec 2009
Posts: 27

PostPosted: Mon Dec 07, 2009 3:55 pm    Post subject: Reply with quote

OK, and this applies to the rest of them like next, first, and last? I can see the rationale behind this.
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 4631
Location: Hamburg / Germany

PostPosted: Mon Dec 07, 2009 4:03 pm    Post subject: Reply with quote

Yes that applies for all special variables related to the foreach and section tag.
Back to top
View user's profile Send private message
httpete
Smarty Rookie


Joined: 05 Dec 2009
Posts: 27

PostPosted: Thu Dec 10, 2009 7:22 pm    Post subject: Warning thrown - line 51 of smarty_method_clear_compiled_tpl Reply with quote

Saw this today

<br /> Warning: substr_compare() [<a href='function.substr-compare'>function.substr-compare</a>]: The length cannot exceed initial string length in /home/hwan/my/root/path/Smarty/sysplugins/smarty_method_clear_compiled_tpl.php on line 51<br />
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 4631
Location: Hamburg / Germany

PostPosted: Fri Dec 11, 2009 2:25 pm    Post subject: Reply with quote

This is fixed in the SVN now
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Smarty 3 All times are GMT
Goto page 1, 2, 3  Next
Page 1 of 3

 
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