Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Smarty Q: Complicated Section Looping

Posted on 2008-10-12
4
Medium Priority
?
692 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

610 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