Solved

Smarty Q: Complicated Section Looping

Posted on 2008-10-12
4
667 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
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 count occurrences of each item in an array.
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…

732 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