Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

How? $smarty.post.value_$smarty.section.role.iteration

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
Scott
Smarty Rookie


Joined: 18 Apr 2003
Posts: 10
Location: Sarasota, FL

PostPosted: Sat May 03, 2003 5:03 am    Post subject: How? $smarty.post.value_$smarty.section.role.iteration Reply with quote

I'm trying to default a checkbox to the previously posted
value of the same form (which is shown again in case of error).
Code:

{ section name=role loop=$role_list }

   <input type="checkbox" value="1" name="contact_role_{$smarty.section.role.iteration}"

   {* WHAT IS USED TO MAKE THIS WORK HERE.... ???? *}
   { if 1 == $smarty.post.contact_role_$smarty.section.role.iteration }
        checked
   { /if }

    >  {* close input checkbox *}

{/section}

I thought backslashes would help, but I get an error:
$smarty.post.contact_role_`$smarty.section.role.iteration`

How can I use iteration to access a dynamic POST value?
Back to top
View user's profile Send private message Visit poster's website
andre
Smarty Pro


Joined: 23 Apr 2003
Posts: 164
Location: Karlsruhe, Germany

PostPosted: Sat May 03, 2003 9:15 am    Post subject: Reply with quote

Replace

Code:
   { if 1 == $smarty.post.contact_role_$smarty.section.role.iteration }
        checked
   { /if }


with

Code:
   {assign var="temp" value="contact_role_`$smarty.section.role.iteration`"}
   {if 1 == $smarty.post.$temp}
       checked
   {/if}


This is the trick Wink
Back to top
View user's profile Send private message
Scott
Smarty Rookie


Joined: 18 Apr 2003
Posts: 10
Location: Sarasota, FL

PostPosted: Sat May 03, 2003 11:19 am    Post subject: Reply with quote

Thanks for the reply, but this doesn't seem to work for me.

Code:

                {assign var="temp" value="contact_role_`$smarty.section.role.iteration`"}
                {if 1 == $smarty.post.$temp}
                    checked
                {/if}

                > {* end of input *}

                temp={$temp}


I see:
temp=contact_role_`1`

The slashes are still part of the string.
I'm using Smarty v2.5.0
Back to top
View user's profile Send private message Visit poster's website
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Sat May 03, 2003 11:20 am    Post subject: Reply with quote

andre wrote:
This is the trick Wink


Yep. http://smarty.php.net/manual/en/language.syntax.quotes.php
Back to top
View user's profile Send private message
Scott
Smarty Rookie


Joined: 18 Apr 2003
Posts: 10
Location: Sarasota, FL

PostPosted: Sat May 03, 2003 2:39 pm    Post subject: This works great! Reply with quote

This does work well!

My test instance was still at version 2.4.2 -- once I upgraded to 2.5.0 it works.

thank you!
Back to top
View user's profile Send private message Visit poster's website
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Sat May 03, 2003 2:53 pm    Post subject: Re: This works great! Reply with quote

Scott wrote:
My test instance was still at version 2.4.2 -- once I upgraded to 2.5.0 it works.


I really should have said that backticks require 2.5.0+. Especially since I thought something was up when you were getting `'s in your output.

I think we should encourage people to add the results of echo $smarty->_version; to their posts Smile
Back to top
View user's profile Send private message
Scott
Smarty Rookie


Joined: 18 Apr 2003
Posts: 10
Location: Sarasota, FL

PostPosted: Tue May 06, 2003 12:39 pm    Post subject: Re: This works great! Reply with quote

boots wrote:


I really should have said that backticks require 2.5.0+. Especially since I thought something was up when you were getting `'s in your output.

I think we should encourage people to add the results of echo $smarty->_version; to their posts Smile


Yes, I agree comletely. This may have saved me time searching for the simple answer of "upgrade to 2.5.0".

I also had several other areas that "broke" with using 2.5.0, such as tests for file existence:

Code:

{ if file_exists("$form.file1") }

is now
Code:

{ if file_exists("`$form.file1`") }
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
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