Page 1 of 1

template use of eval against assign

Posted: Thu Jun 30, 2011 3:45 pm
by Timbalu
I just read an interesting thread about smarty memory consumption, reading
The {eval} tag is consuming a lot of memory as it loads and executes the compiler each time the template gets rendered. This is true for both versions Smarty2 and Smarty3.
The only {eval } I found is used in bulletproof/entries.tpl pagination section.
Since eval will be forbidden by default in Smarty3.1, could we just replace it now with {assign }, to be future compatible, without breaking something?

Code: Select all

        <div class="pagination">
            {* eval var=$footer_currentPage-3 assign="paginationStartPage" *}
            {assign var="paginationStartPage" value="`$footer_currentPage-3`"}
            {if $footer_currentPage+3 > $footer_totalPages}
                {* eval var=$footer_totalPages-6 assign="paginationStartPage" *}
                {assign var="paginationStartPage" value="`$footer_totalPages-6`"}
            {/if}
            {if $paginationStartPage <= 0}
                {assign var="paginationStartPage" value="1"}
            {/if}
            ...
This does work in Smarty2 and Smarty3, but I am not sure about compiling and cache issues.

Re: template use of eval against assign

Posted: Thu Jun 30, 2011 7:44 pm
by yellowled
Timbalu wrote:This does work in Smarty2 and Smarty3, but I am not sure about compiling and cache issues.
If there are no further concerns, feel free to commit it. I'm swamped right now.

YL

Re: template use of eval against assign

Posted: Sat Jul 02, 2011 7:43 pm
by Don Chambers
Timbalu wrote:

Code: Select all

        <div class="pagination">
            {* eval var=$footer_currentPage-3 assign="paginationStartPage" *}
            {assign var="paginationStartPage" value=$footer_currentPage-3}
            {if $footer_currentPage+3 > $footer_totalPages}
                {* eval var=$footer_totalPages-6 assign="paginationStartPage" *}
                {assign var="paginationStartPage" value=$footer_currentPage-6}
            {/if}
            ...
I have not tried that.. in that second {assign}, does $footer_totalPages-6 and $footer_currentPage-6 always resolve to the same thing, or is that a typo?

Re: template use of eval against assign

Posted: Sun Jul 03, 2011 9:36 am
by Timbalu
Oh no, thanks for taking notice.
Thats a typo here in my pasted code. I just copied the first one...
Its $footer_totalPages-6 and I did now correct my original post (and added quotes and backticks).

Don, why did you use eval there, can you remember the reason?

Re: template use of eval against assign

Posted: Mon Jul 04, 2011 3:41 am
by Don Chambers
Timbalu wrote:Oh no, thanks for taking notice.
Thats a typo here in my pasted code. I just copied the first one...
Its $footer_totalPages-6 and I did now correct my original post (and added quotes and backticks).

Don, why did you use eval there, can you remember the reason?
Actually, I have used assign in my templates... I think Yellowled worked out that pagination code.... I had nothing to do with it, other than possibly adding some css to the bulletproof colorsets for it. Why are the backticks necessary?

Re: template use of eval against assign

Posted: Mon Jul 04, 2011 10:37 am
by Timbalu
Don Chambers wrote:Why are the backticks necessary?
To say smarty parse the inbetween like being in {}. Its not only a pre set var, its an operation.
They have to be there if you set "todo" vars into quotes. In this case we don't really need quotes and backticks in smarty2, but I remembered to have read Smarty3 beeing picky about missing quotes (not really sure about it). Thats why I added them. Normally in Smarty2 the backticks are necessary when using ~value="$var.foo".

I'd still like to know why Yellowled set eval there.

Re: template use of eval against assign

Posted: Tue May 15, 2012 5:40 pm
by Don Chambers
I don't think this was ever resolved. I was using the bp pagination code in one of my templates, and recently changed {eval} to {assign} as shown in Ian's example above. It works perfectly.

Was there a reason it was not committed? I would add it myself, but I have yet to commit anything using github.

Re: template use of eval against assign

Posted: Tue May 15, 2012 5:57 pm
by Timbalu
No. There never was much feedback on this. Shall I commit it then?

Re: template use of eval against assign

Posted: Tue May 15, 2012 6:00 pm
by Don Chambers
yep - how exactly do we do that now in github?

Re: template use of eval against assign

Posted: Tue May 15, 2012 6:24 pm
by Timbalu
I do it this way:

Code: Select all

$ git checkout master
Switched to branch 'master'

$ git pull origin master
+ change file(s) and commit them
$ git commit -am "commit name blah blah"
$ git push origin master

$ git checkout 2.0
Switched to branch '2.0'

$ git pull origin 2.0
$ git cherry-pick <commit from master>
$ git push origin 2.0

Re: template use of eval against assign

Posted: Tue May 15, 2012 7:40 pm
by yellowled
Two small notes:
Timbalu wrote:

Code: Select all

$ git checkout master
$ git pull origin master

Code: Select all

$ git pull
should actually suffice. Same with 'git push'.
Timbalu wrote:

Code: Select all

$ git commit -am "commit name blah blah"
Of course, this is just an example commit message, and the following does not relate to anyone's commit messages in particular, but sometimes I wouldn't mind if people were just a tad more verbose in their commit messages.

At some point in the future, we might actually need them to figure out some stuff we committed. By then, something like "Fixed." won't help us much, especially if we're trying to figure out somebody else's commits. :)

There is a theoretical length limit for commit messages, and I'm not saying anybody should post the Bhagavad Gita or something. Just be a bit more verbose, everybody. Your future selves will thank you. :)

YL