Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Re: [SMARTY] Sections and checkboxes
Erich Beyrent writes:
> I have two arrays that get assigned to my template - one containing
> platforms, the other containing supported platforms.  I am trying to loop
> through both arrays and check the supported platforms.
>
> {section name=i loop=$Platforms}
>   {section name=j loop=$SupportedPlatforms}
>     {if $SupportedPlatforms[j].platformName == $Platforms[i].platformName}
>       {$Platforms[i].platformName}
>       <input type=checkbox value="{$Platforms[i].platformID"
> name="Platforms[]" checked>
>     {else}
>       <input type=checkbox value="{$Platforms[i].platformID"
> name="Platforms[]">
>     {/if}
>   {/section}
> {/section}
>
> This works, but displays two checkboxes for supported platforms.  Is there
a
> way to break out of the section loop, or is there perhaps a better/easier
> way to accomplish my task?

There's a typo in there somewhere:
<input type=checkbox value="{$Platforms[i].platformID">
name="Platforms[]" checked>
.. shouldn't parse (missed closing }).

In any case it looks to me like you'll get N checkboxes for each platform,
where N is the number of supported platforms, since each time through each
look is currently set to display something.

My recommendation is to provide better data to your template than try to
work through this in the template code, but the following might work:

{section name=i loop=$Platforms}
{assign var=printed value=false}
{section name=j loop=$SupportedPlatforms}
{if $SupportedPlatforms[j].platformName == $Platforms[i].platformName}
{$Platforms[i].platformName}
<input type=checkbox value="{$Platforms[i].platformID"
name="Platforms[]" checked>
{assign var=printed value=true}
{/if}
{/section}
{if not $printed}
<input type=checkbox value="{$Platforms[i].platformID"
name="Platforms[]">
{/if}
{/section}

.. although I have a suspicion that I'm not really understanding what you'r
e
trying to output here. Maybe the above will give you a clue, anyhow.

--
Mark Rogers,
More Solutions Ltd :: Tel: 0845 45 89 555

Report this thread to moderator Post Follow-up to this message
Old Post
Mark Rogers
12-17-04 01:58 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PHP Smarty Templates archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 07:37 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.