template use of eval against assign

Discussion corner for Developers of Serendipity.
Post Reply
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

template use of eval against assign

Post 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.
Last edited by Timbalu on Sun Jul 03, 2011 11:52 am, edited 2 times in total.
Regards,
Ian

Serendipity Styx Edition and additional_plugins @ https://ophian.github.io/ @ https://github.com/ophian
yellowled
Regular
Posts: 7111
Joined: Fri Jan 13, 2006 11:46 am
Location: Eutin, Germany
Contact:

Re: template use of eval against assign

Post 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
Don Chambers
Regular
Posts: 3652
Joined: Mon Feb 13, 2006 2:40 am
Location: Chicago, IL, USA
Contact:

Re: template use of eval against assign

Post 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?
=Don=
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: template use of eval against assign

Post 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?
Regards,
Ian

Serendipity Styx Edition and additional_plugins @ https://ophian.github.io/ @ https://github.com/ophian
Don Chambers
Regular
Posts: 3652
Joined: Mon Feb 13, 2006 2:40 am
Location: Chicago, IL, USA
Contact:

Re: template use of eval against assign

Post 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?
=Don=
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: template use of eval against assign

Post 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.
Regards,
Ian

Serendipity Styx Edition and additional_plugins @ https://ophian.github.io/ @ https://github.com/ophian
Don Chambers
Regular
Posts: 3652
Joined: Mon Feb 13, 2006 2:40 am
Location: Chicago, IL, USA
Contact:

Re: template use of eval against assign

Post 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.
=Don=
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: template use of eval against assign

Post by Timbalu »

No. There never was much feedback on this. Shall I commit it then?
Regards,
Ian

Serendipity Styx Edition and additional_plugins @ https://ophian.github.io/ @ https://github.com/ophian
Don Chambers
Regular
Posts: 3652
Joined: Mon Feb 13, 2006 2:40 am
Location: Chicago, IL, USA
Contact:

Re: template use of eval against assign

Post by Don Chambers »

yep - how exactly do we do that now in github?
=Don=
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: template use of eval against assign

Post 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
Regards,
Ian

Serendipity Styx Edition and additional_plugins @ https://ophian.github.io/ @ https://github.com/ophian
yellowled
Regular
Posts: 7111
Joined: Fri Jan 13, 2006 11:46 am
Location: Eutin, Germany
Contact:

Re: template use of eval against assign

Post 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
Post Reply