This question is answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 10 - Pages: 1 - Last Post: 9 Aug 21, 14:26 Last Post By: JeffTucker Threads: [ Previous | Next ]
JeffTucker

Posts: 8,010
Registered: 31-Jan-2006
Break out of iterator loop?
Posted: 8 Aug 21, 16:41
 
  Click to reply to this thread Reply
I may not end up needing this (still tinkering), but is there a way to break out of a file iterator loop? For example, I want to iterate over all the objects on the current page, but if I find the condition I'm looking for, there's no reason to continue the iteration. For example, checking to see if there are any thumbnail image comments on this page:
<ja:fileiterator>
     <ja:if exists="comment">
          Found one!
          break;
     </ja:if>
</ja:fileiterator>
If it's not page-restricted, I would just use an ordinary ao.getChildren() "for" loop, where breaking out is simple.
JeffTucker

Posts: 8,010
Registered: 31-Jan-2006
Re: Break out of iterator loop?
Posted: 8 Aug 21, 16:46   in response to: JeffTucker in response to: JeffTucker
 
  Click to reply to this thread Reply
BTW, one of the problems with getChildren() is that there doesn't seem to be a getChildren(currentPage) option. Not needed very often these days, since multiple index pages have bitten the dust in most skins, but....
RobM

Posts: 3,877
Registered: 4-Aug-2006
Re: Break out of iterator loop?
Posted: 8 Aug 21, 18:49   in response to: JeffTucker in response to: JeffTucker
 
  Click to reply to this thread Reply
I think this might have to be a feature request :(
JeffTucker

Posts: 8,010
Registered: 31-Jan-2006
Re: Break out of iterator loop?
Posted: 8 Aug 21, 19:05   in response to: RobM in response to: RobM
 
  Click to reply to this thread Reply
I suspected as much, but wanted to make sure I wasn't just forgetting something. These days, I'm usually doing my own tree traversals, and don't use the regular tags very often, so it's all a little rusty.

I did once solve the "children on this page" problem, but it's so convoluted, I hate to resort to it again:

https://jalbum.net/forum/thread.jspa?messageID=298359&#298359

Testing something like that might be enough to drive a developer mad.
RobM

Posts: 3,877
Registered: 4-Aug-2006
Re: Break out of iterator loop?
Posted: 8 Aug 21, 19:38   in response to: JeffTucker in response to: JeffTucker
 
  Click to reply to this thread Reply
JeffTucker wrote:
I suspected as much, but wanted to make sure I wasn't just forgetting something. These days, I'm usually doing my own tree traversals, and don't use the regular tags very often, so it's all a little rusty.

I did once solve the "children on this page" problem, but it's so convoluted, I hate to resort to it again:

https://jalbum.net/forum/thread.jspa?messageID=298359&#298359

Testing something like that might be enough to drive a developer mad.

And files can be hidden now, not just folders!
RobM

Posts: 3,877
Registered: 4-Aug-2006
Re: Break out of iterator loop?
Posted: 8 Aug 21, 19:52   in response to: RobM in response to: RobM
 
  Click to reply to this thread Reply
I don't know if it is possible to use the count option in the iterator, you would need to be able to access the internal counter and set it higher than the count value. I think all those variables are hidden though.
JeffTucker

Posts: 8,010
Registered: 31-Jan-2006
Re: Break out of iterator loop?
Posted: 8 Aug 21, 19:55   in response to: RobM in response to: RobM
 
  Click to reply to this thread Reply
RobM wrote:
And files can be hidden now, not just folders!

That's true just of "pages," isn't it? That includes web locations. I haven't addressed that in any of my skins, but none of them supports extra pages, anyway, and web locations are a separate kind of beast. Tough to think of the situation in which someone would want to have a web location object, but hide it - the core isn't going to "process" it in any fashion.
JeffTucker

Posts: 8,010
Registered: 31-Jan-2006
Re: Break out of iterator loop?
Posted: 8 Aug 21, 21:57   in response to: JeffTucker in response to: JeffTucker
 
  Click to reply to this thread Reply
I'll leave this marked "unanswered" for now. But I realized that I was going to extraordinary lengths to address a fairly extreme fringe case that no normal user is ever likely to encounter. And even if someone did, the effects could be addressed with a single line of custom CSS with an !important stuck on the end of it, so it's really not worth the tsuris.
davidekholm

Posts: 3,804
Registered: 18-Oct-2002
Re: Break out of iterator loop?
Posted: 9 Aug 21, 14:13   in response to: JeffTucker in response to: JeffTucker
 
  Click to reply to this thread Reply
I don't remember that I've implemented any ja:break tag, so you'd have to manually iterate using getChildren(). I'm willing however to implement a ja:break as it's to be expected to exist whenever there are iterators around.
JeffTucker

Posts: 8,010
Registered: 31-Jan-2006
Re: Break out of iterator loop?
Posted: 9 Aug 21, 14:17   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
Do it only if it's really, really easy. This is the first time in over 15 years that I've thought that I might need such a tag, and it turns out that I didn't need it anyway.

But yes, any looping structure probably should have a way to bail out.
JeffTucker

Posts: 8,010
Registered: 31-Jan-2006
Re: Break out of iterator loop?
Posted: 9 Aug 21, 14:26   in response to: JeffTucker in response to: JeffTucker
 
  Click to reply to this thread Reply
What would probably be somewhat more useful is a method to let the skin do its own iteration over the objects on the current page. If the skin isn't doing multiple index pages, there's no problem - you just iterate over the children from predir.bsh. But things get messy when you are producing multiple index pages, and need to traverse only the piece of the tree that will be shown on the current page.

Probably not worth the effort, however. There are almost no remaining skins that support multiple index pages at a given level.
Legend
Forum admins
Helpful Answer
Correct Answer

Point your RSS reader here for a feed of the latest messages in all forums