Solved

Smarty Q: Complicated Section Looping

Posted on 2008-10-12
4
646 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:Squinky
Comment Utility
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
Comment Utility
It's just two menus.  I'm building an array for a js function.
0
 
LVL 25

Expert Comment

by:Squinky
Comment Utility
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
Comment Utility
I wound up figuring out what I wanted to do.  Thanks anyway.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

772 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

13 Experts available now in Live!

Get 1:1 Help Now