Solved

Smarty Q: Complicated Section Looping

Posted on 2008-10-12
4
649 Views
Last Modified: 2013-11-10
This might be a little hard to follow...

Basically, I have two menus: FromYear and ToYear.

When the FromYear is selected, the values of the ToYear select fields will change, depending upon the FromYear value.  I pretty much have it working the way that I want, except that I need to insert a comma, *only* if it *isn't* the last item in the array.

The problem is, that the the ToYear values also must meet the condition of being greater than or equal to the FromYear value.  So, the loop never "sees" the last item in the array because of this other conditional statement.  

Right now, the template looks like this:

{section name=i loop=2010 max=40 step=-1}

	fromyear.forValue("{$smarty.section.i.index}").addOptions(

		{section name=ii loop=2009 max=39 step=-1}

			{if $smarty.section.ii.last}

				{if $smarty.section.ii.index >= $smarty.section.i.index}"{$smarty.section.ii.index}"{/if}

			{else}

				{if $smarty.section.ii.index >= $smarty.section.i.index}"{$smarty.section.ii.index}",{/if}

			{/if}

		{/section});

{/section}

Open in new window

0
Comment
Question by:jen_jen_jen
  • 2
  • 2
4 Comments
 
LVL 25

Expert Comment

by:Marcus Bointon
ID: 22703558
I don't get your structure - it looks like you're generating a large number of menus, not just two. If it was just two, then I'd expect the loops to be sequential, not nested. Then when a new FromYear is selected, I'd use Javascript to dynamically repopulate the option list of the ToYear menu.

That said, I'm still a little confused as the fact that you're using commas in the output makes it look like you're not using HTML selects... Can you give a bit more context?
0
 

Author Comment

by:jen_jen_jen
ID: 22706233
It's just two menus.  I'm building an array for a js function.
0
 
LVL 25

Expert Comment

by:Marcus Bointon
ID: 22707088
ok, but you're saying that the content of the second menu will change when you select something in the first, which is something that happens after Smarty's involvement has ended?

Aside from that I think it looks like it would be easier to generate this list by pre-filling some arrays with your years and using implode. That's much easier than using Smarty syntax to do the same thing.
0
 

Accepted Solution

by:
jen_jen_jen earned 0 total points
ID: 22712944
I wound up figuring out what I wanted to do.  Thanks anyway.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
This article discusses four methods for overlaying images in a container on a web page
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now