1 of 2
1
Loops in templates
Posted: 27 March 2008 05:36 AM   [ Ignore ]  
Lab Assistant
Avatar
RankRank
Total Posts:  250
Joined  09-29-2007

The only way of putting repetative numerical values into templates is either by hard-coding them in or by enabling and using php to do it. I always try to avoid enabling php in templates for security purposes, and hard-coding in for example a drop-down select box with 100 values is never fun.

So i have developed a loop plugin that solves the problem by allowing you to perform loops in your templates. Its a free download here:

http://www.putyourlightson.net/projects/loop

 Signature 

* Get FireMail for EE 2.0 and manage and track emails in real-time. Get the Sitemap Module and improve your site’s SEO

More Add-ons: Multi Language, Exchange Rates, Stand-Alone Image Editor, Landing Page, iWebApp, LogMeIn, Loop Plugin, Session Variables

Profile
 
 
Posted: 27 March 2008 05:38 AM   [ Ignore ]   [ # 1 ]  
Moderator
Avatar
RankRankRankRankRankRankRank
Total Posts:  29212
Joined  05-15-2004

Interesting, but shouldn’t that go in the Plugins forum?

 Signature 

ExpressionEngine 2.0 Downloads | Docs | Bugtracker

“If the English language made any sense, lackadaisical would have something to do with a shortage of flowers.” (Doug Larson)

Profile
MSG
 
 
Posted: 27 March 2008 06:04 AM   [ Ignore ]   [ # 2 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  918
Joined  02-05-2002

Hi Ben,

Great Add-On!

A few notes:
1) when using the plugin inside a weblog tag (or query tag), the {count} variable will show the weblog’s {count} variable, you could change yours to something like {loop_count} or {counter}.
2) you might also want to start prefixing your EE Add-Ons smile

Now let’s see if we can use this plugin to easily create multiple columns of weblog entries cool smirk

Cheers!

 Signature 

Member of the EE Pro Network

Profile
 
 
Posted: 27 March 2008 06:31 AM   [ Ignore ]   [ # 3 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  250
Joined  09-29-2007

thanks for the suggestions.  i’ve changed the file name to pi.for_loop.php and the variable to {loop_count}.

please feel free to post any cool uses of the plugin, i expect there might be a few!!

 Signature 

* Get FireMail for EE 2.0 and manage and track emails in real-time. Get the Sitemap Module and improve your site’s SEO

More Add-ons: Multi Language, Exchange Rates, Stand-Alone Image Editor, Landing Page, iWebApp, LogMeIn, Loop Plugin, Session Variables

Profile
 
 
Posted: 27 March 2008 06:41 AM   [ Ignore ]   [ # 4 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  918
Joined  02-05-2002

Hi ben,

From the Developer Guidelines: (although I don’t think it is a requirement)

“Choose a prefix that is unique to your identity as a developer or company”

...so why not pi.bc_loop.php or pi.pylo_loop.php?

I just tested the plugin with some rating value (0 to 5), pretty cool.

{exp:loop start="0" end="{rating}" increment="1"}
<img src="star.gif" />
{/exp:loop}
 Signature 

Member of the EE Pro Network

Profile
 
 
Posted: 27 March 2008 06:44 AM   [ Ignore ]   [ # 5 ]  
Professor
Avatar
RankRankRankRankRankRankRank
Total Posts:  10829
Joined  04-15-2006

Hi Ben,

Looks set to be a really great little add-on! Well done.

One little thing though and this is me just nitpicking but on your page it says “repetative numerical” instead of “repetitive numerical” wink

Great plugin though and definitely one I will use so thanks for that.

Best wishes,

Mark

 Signature 

Shopping Cart Plugin
Full list of add-ons
———————————————————-
Buy me a drink, or two if you like!!

Profile
 
 
Posted: 27 March 2008 06:48 AM   [ Ignore ]   [ # 6 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  250
Joined  09-29-2007

...so why not pi.bc_loop.php or pi.pylo_loop.php?

i think the file name and the exp tag should be intuitive so that it is easier to understand when seen in a template.  for_loop actually describes it pretty well since three values (initial, limit, increment) have to be set, and i assume most people have heard of a for loop, but maybe not…?

@mark: that really is nitpicking but i’ll change it just for you!!

 Signature 

* Get FireMail for EE 2.0 and manage and track emails in real-time. Get the Sitemap Module and improve your site’s SEO

More Add-ons: Multi Language, Exchange Rates, Stand-Alone Image Editor, Landing Page, iWebApp, LogMeIn, Loop Plugin, Session Variables

Profile
 
 
Posted: 27 March 2008 06:54 AM   [ Ignore ]   [ # 7 ]  
Professor
Avatar
RankRankRankRankRankRankRank
Total Posts:  10829
Joined  04-15-2006
ben c - 27 March 2008 06:48 AM

@mark: that really is nitpicking but i’ll change it just for you!!

So shoot me wink

Actually just kidding, don’t shoot me please!! I have just always been one to notice spelling mistakes and sometimes I really should just keep my g*b shut. Working in radio advertising it has become a staple part of everyday life for me unfortunately!

I’ll bet I’ve probably made some mistakes in this post anyway so will cower off into the corner now!!

Again, great plugin (shouldn’t this word really be plug-in?) though so thanks for that!

Best wishes,

Mark

 Signature 

Shopping Cart Plugin
Full list of add-ons
———————————————————-
Buy me a drink, or two if you like!!

Profile
 
 
Posted: 27 March 2008 06:55 AM   [ Ignore ]   [ # 8 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  918
Joined  02-05-2002

Ben,

The name being so intuitive is exactly why you should prefix it wink

Again from the Guidlines:

When your class or filename is a common word, or might quite likely be identically named in another PHP script, provide a unique prefix to help prevent collision. Always realize that your end users may be running other add-ons or third party PHP scripts.

I’m not trying to annoy you, just hoping that all EE devs start prefix their add-ons with a personal prefix like the Guidelines propose.
Most EE devs are already doing this…

*ducks and starts updating his own add-ons wink

 Signature 

Member of the EE Pro Network

Profile
 
 
Posted: 27 March 2008 07:02 AM   [ Ignore ]   [ # 9 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  250
Joined  09-29-2007

haha, ok i’ll consider it, thanks cocoa

cheers mark!

 Signature 

* Get FireMail for EE 2.0 and manage and track emails in real-time. Get the Sitemap Module and improve your site’s SEO

More Add-ons: Multi Language, Exchange Rates, Stand-Alone Image Editor, Landing Page, iWebApp, LogMeIn, Loop Plugin, Session Variables

Profile
 
 
Posted: 27 March 2008 07:35 AM   [ Ignore ]   [ # 10 ]  
Professor
Avatar
RankRankRankRankRankRankRank
Total Posts:  10829
Joined  04-15-2006
ben c - 27 March 2008 07:02 AM

cheers mark!

I’m sure you don’t really mean that! wink
I can hear you scraping away at my Avatar on screen trying to gouge out my eyes!! grin

Best wishes,

Mark

 Signature 

Shopping Cart Plugin
Full list of add-ons
———————————————————-
Buy me a drink, or two if you like!!

Profile
 
 
Posted: 27 March 2008 11:02 AM   [ Ignore ]   [ # 11 ]  
Administrator
Avatar
RankRankRankRankRankRankRank
Total Posts:  19293
Joined  06-03-2002

Moved to the Plugins forum.  Ben, after you’ve assembled the feedback and are happy with your plugin, don’t forget to submit it to the Add-On Library!

 Signature 
Profile
MSG
 
 
Posted: 07 December 2008 02:45 PM   [ Ignore ]   [ # 12 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  282
Joined  06-15-2008

Ben,

Great stuff. I’ve come up against a problem, although it could be related to the way EE parses custom fields.

I want to display a list of testimonials, say 10 of them on a page. I’ve named each custom field testimonial_X, where X is the index of the for loop.

My code looks like this:

{exp:for_loop start="1" end="10" increment="1"}
    
<li class="testimonial">
        
{testimonial_{index}}
    
</li>
{/exp:for_loop}

Instead of outputting the testimonial content, I just get:

{testimonial_1}
{testimonial_2}
{testimonial_3}
etc…

Am I doing this right, or is what I’m trying to do not possible?

Thanks!

 Signature 

RYAN BURNEY • Lead Web Developer, 3 Roads Media
Denver based web and graphic design

Profile
 
 
Posted: 27 February 2009 03:47 AM   [ Ignore ]   [ # 13 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  881
Joined  02-02-2007

Hi Ben,

I have an idea how to make Loop plugin more powerful.

Let’s consider an example. Say, there is “my_weblog” weblog in which there are used custom fields whose names are as follows:

custom_field_1
custom_field_2
custom_field_3
...
custom_field_49
custom_field_50

Now say the code as this is needed:

{exp:weblog:entries weblog="my_weblog" url_title="{segment_3}"}
{if custom_field_1
!= ""}{custom_field_1}{/if}<br>
{if custom_field_2 != ""}{custom_field_2}{/if}<br>
{if custom_field_3 != ""}{custom_field_3}{/if}<br>
...
{if custom_field_49 != ""}{custom_field_49}{/if}<br>
{if custom_field_50 != ""}{custom_field_50}{/if}<br>
{/exp:weblog:entries}

It is natural to use in such situation Loop plugin. But because of the parse order the code as this will not work:

{exp:weblog:entries weblog="my_weblog" url_title="{segment_3}"}
{exp
:for_loop start="1" end="50" increment="1"}
{if custom_field_{index}
!= ""}{custom_field_{index}}{/if}<br>
{/exp:for_loop}
{
/exp:weblog:entries}

This code will work:

{exp:for_loop start="1" end="50" increment="1" parse="inward"}
{exp
:weblog:entries weblog="my_weblog" url_title="{segment_3}"}
{if custom_field_{index}
!= ""}{custom_field_{index}}{/if}<br>
{/exp:weblog:entries}
{
/exp:for_loop}

But this code will be inefficient since exp:weblog:entries will be initiated 50 times.

The problem could be solved by introducing optional variable pair - {loop_area}{/loop_area} - which would be used for marking portion of tagdata which should be iterated:

{exp:for_loop start="1" end="50" increment="1" parse="inward"}
{exp
:weblog:entries weblog="my_weblog" url_title="{segment_3}"}
{loop_area}
{if custom_field_{index}
!= ""}{custom_field_{index}}{/if}<br>
{/loop_area}
{
/exp:weblog:entries}
{
/exp:for_loop}

This way would be no performance loss since exp:weblog:entries would be initiated only once.

If you would be interested in such enhancement of your plugin, I can do the necessary coding.

 Signature 

Full list of add-ons here

Child Categories
Browser Sniff
Category Id
Entries Number

Profile
 
 
Posted: 27 February 2009 10:34 AM   [ Ignore ]   [ # 14 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  282
Joined  06-15-2008

I’ve since come across the LG Data Matrix extension, which renders many loop situations moot. I’d strongly recommend anyone check into this one.

 Signature 

RYAN BURNEY • Lead Web Developer, 3 Roads Media
Denver based web and graphic design

Profile
 
 
Posted: 03 March 2009 05:01 AM   [ Ignore ]   [ # 15 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  250
Joined  09-29-2007

hi Laisvunas and thanks for your suggestion. if you would like to add this functionality then please feel free to. its a pity that the nested plugins parse order isn’t adhered to in this case.

 Signature 

* Get FireMail for EE 2.0 and manage and track emails in real-time. Get the Sitemap Module and improve your site’s SEO

More Add-ons: Multi Language, Exchange Rates, Stand-Alone Image Editor, Landing Page, iWebApp, LogMeIn, Loop Plugin, Session Variables

Profile
 
 
Posted: 03 March 2009 05:41 AM   [ Ignore ]   [ # 16 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  881
Joined  02-02-2007

Hi Ben,

I sent you a private message with a version of Loop plugin in which I implemented the functionality described in my post.

If you like my idea and if my code is OK, would you like to include my additions into Loop plugin?

 Signature 

Full list of add-ons here

Child Categories
Browser Sniff
Category Id
Entries Number

Profile
 
 
Posted: 12 March 2009 03:40 PM   [ Ignore ]   [ # 17 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  881
Joined  02-02-2007

Hi all,

I released a fork of For Loop plugin, called Loop Plus, in which my suggestions outlined in this post are implemented.

You can download it from this forum thread.

 Signature 

Full list of add-ons here

Child Categories
Browser Sniff
Category Id
Entries Number

Profile
 
 
Posted: 13 March 2009 06:29 AM   [ Ignore ]   [ # 18 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  250
Joined  09-29-2007

thanks laisvunas, nice that people are extending my code and sharing it!

 Signature 

* Get FireMail for EE 2.0 and manage and track emails in real-time. Get the Sitemap Module and improve your site’s SEO

More Add-ons: Multi Language, Exchange Rates, Stand-Alone Image Editor, Landing Page, iWebApp, LogMeIn, Loop Plugin, Session Variables

Profile
 
 
   
1 of 2
1
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 1743, on December 02, 2009 03:47 PM
Total Registered Members: 120363 Total Logged-in Users: 74
Total Topics: 126488 Total Anonymous Users: 34
Total Replies: 665186 Total Guests: 343
Total Posts: 791674    
Members ( View Memberlist )