Solved

Smarty Q: Complicated Section Looping

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to use embargo Date/time in php 29 38
PHP populating an array. 4 25
Advice and best practice  SQLite3 Database using PHP 2 48
Dynamic varibles 5 32
Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
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 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…

773 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