The following warnings occurred: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Warning [2] Undefined array key "avatartype" - Line: 783 - File: global.php PHP 8.1.31 (Linux)
|
Foreach or not foreach ? - smarty template - Printable Version +- Form Tools (https://forums.formtools.org) +-- Forum: Form Tools (https://forums.formtools.org/forumdisplay.php?fid=1) +--- Forum: General Discussion (https://forums.formtools.org/forumdisplay.php?fid=5) +--- Thread: Foreach or not foreach ? - smarty template (/showthread.php?tid=1489) |
Foreach or not foreach ? - smarty template - Lina - Jul 31st, 2011 Hello, everyday I'm better in Form Tools coding and formatting, but here is the problem I can't handle. I need to print specific output of submissions (one submission per page). "Additional text here" is not a part of field title and I need to be able to change it in different views. I made new export type and I'm trying to change smarty template to work for me. Here is my code: Code: {* loop through all submissions in the current result set *} 1. The field "country" is dropdown field type and I need it to show selected option display text not field value. I know it has something to do with function.smart_display_field_values.php, but how to do it? The code: Code: {if $col_name == "country"} does display it correctly, but only positioned in "foreach" function, but I need it between <td> tags. 2. The field "client number" is field from clients table stored with each submission in submissions table. Could I somehow include in this output additional fields from clients "on the fly" (I suppose the right expression is "from session" ) or it should be better to store them in submission table? Administrator doesn't need this output, just clients, so maybe it could be done? Thanks for any help! Lina RE: Foreach or not foreach ? - smarty template - Ben - Jul 31st, 2011 Hi Lina, Great questions! So for the first one, how about just moving the foreach block into the appropriate spot (within the <td></td>)? If it's outputting it properly, would that work? Try this: Code: {* loop through all submissions in the current result set *} But I'm kind of surprised that this works... Code: {smart_display_field_values field_id=$field_id selected=$submission.country} I've have thought that in the context, you'd need to use: Code: {smart_display_field_values field_id=$field_id selected=$value} But whatever works! For the second question - yes, pulling them out of sessions would have been my first guess, too. However I just looked over the code and the sessions aren't being passed to the template, so I'm afraid you can't. But this is very reasonable indeed. I'm going to jot it down as a feature request so I can include it in a new version. Stashing the client information in separate database fields would certainly work, but it would be such a shame - and a terrible hack...! Sorry I couldn't be more help on that. Let me know how the first issue goes. - Ben RE: Foreach or not foreach ? - smarty template - Lina - Jul 31st, 2011 Hello Ben! Thank you for reply About first question - the code between <td> tags you suggested works fine. Here it is: Code: {foreach from=$display_fields item=field name=col_row} but here is my version of code that also works between <td> tags (I was playing with my template before I got your reply. ): Code: {foreach from=$display_fields item=field name=col_row} I'm VERY new to smarty templates, so please help me decide which one is better. I also thought this code: Code: {foreach from=$display_fields item=field name=col_row} should be on the beginning of template (+ code between td tags), but obviously not, so I deleted it. Thanks! About my second question: The code: Code: {$smarty.session.ft.account.account_id} WORKS in template. It displays id, first and last name and email of the client! I got idea from your reply to another thread. You posted code similar to this: Code: <?php So, I tried to make it in smarty - I have special trial and error method , but I also need some additional fields from Extended Client Fields. Any ideas how to do it? Thank you VERY MUCH, Lina I got it! My special method, remember? This is code to display id, first and last name and email of the client: Code: {$smarty.session.ft.account.account_id} and this is code to display fields from Extended Client Fields Module: Code: {$smarty.session.ft.account.settings.ecf_1} It works great in my template, but please check all of my template code. I don't want to run into problems later. Thank you sooooo much for Form Tools, Lina RE: Foreach or not foreach ? - smarty template - Ben - Aug 2nd, 2011 Excellent! Sounds like you made loads of progress! Quote:I'm VERY new to smarty templates, so please help me decide which one is better. Yours! All those declared variables weren't needed, so yours is more readable (and a teany bit faster) And haha, very well done sniffing out the use of the $smarty.session.ft space. I totally didn't spot that. Very well done indeed - I'm going to start asking you questions soon (you think I'm joking, but maybe not... ) - Ben RE: Foreach or not foreach ? - smarty template - Lina - Aug 4th, 2011 Ben, thank you sooo much for your kind reply, but you are still master for me I have a new problem: There is a small dropdown list in my form with field values / display text 0/A and 1/B. When option A is selected, it doesn't work in any of prebuilt smarty templates - the field value is displayed instead of display text. It works fine for option B. Both options are displayed correctly on edit submissions page. I suppose there is a problem in function.smart_display_field_values.php but I don't know how to fix it. Maybe you could check it out? Anyway, thank you for cool and fantastic script Lina RE: Foreach or not foreach ? - smarty template - Lina - Aug 5th, 2011 I found it! PHP.net manual is a great thing! In file function.smart_display_field_values.php: Code: if (empty($selected)) should be replaced with: Code: if (empty($selected) && !is_numeric($selected)) because value 0 is treated as empty. I love FormTools. Viva La Canada! Lina RE: Foreach or not foreach ? - smarty template - Ben - Aug 5th, 2011 haha excellent. Glad you got it sorted out! - Ben |