We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Plugin: Loop Plus

Development and Programming

Laisvunas's avatar
Laisvunas
879 posts
16 years ago
Laisvunas's avatar Laisvunas

The attached add-on files may be out of date. Please visit Devot-ee for the latest versions.

Hi,

I have rewritten ben’s For Loop plugin. The result is Loop Plus plugin.

PARAMETERS

1) start - Optional. Represents the starting value of the index. The default value is 1.

2) end - Optional. Represents the end value or limit of the index. The default value is 3.

3) increment - Optional. Represents the incremental value of the index on each iteration of the loop. The default value is 1.

VARIABLES

1) {index} - used to get the value of the index that is incremented in each iteration of the loop.

2) {loop_count} - used to get the number of times that the loop has been iterated over.

VARIABLE PAIR

1) {loop_area}{/loop_area} - Optional. Used to mark area which should be iterated.

USAGE

Use as follows:

{exp:loop_plus start="5" end="10" increment="1"}
This loop has been executed {loop_count} times and is now on iteration number {index}.
{/exp:loop_plus}

Or use {loop_area}{/loop_area} variable pair to mark an area which should be looped:

{exp:loop_plus start="5" end="10" increment="1"}
Some code
{loop_area}
This loop has been executed {loop_count} times and is now on iteration number {index}.
{/loop_area}
Some code
{/exp:loop_plus}

WHY NEW LOOPING PLUGIN?

I was dissatisfied with the original plugin because using it was not possible to output efficiently the code as this:

{exp:weblog:entries weblog="my_weblog" url_title="{segment_3}"}
{if custom_field_1 != ""}{custom_field_1}{/if}

{if custom_field_2 != ""}{custom_field_2}{/if}

{if custom_field_3 != ""}{custom_field_3}{/if}

...
{if custom_field_49 != ""}{custom_field_49}{/if}

{if custom_field_50 != ""}{custom_field_50}{/if}

{/exp:weblog:entries}

Because of the parse order the code as this did 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}

{/exp:for_loop}
{/exp:weblog:entries}

This code worked:

{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}

{/exp:weblog:entries}
{/exp:for_loop}

But it was inefficient since exp:weblog:entries were initiated on each iteration.

Loop Plus plugin solves this problem by introducing optional {loop_area}{/loop_area} variable pair. Using it it is possible to write the code as this:

{exp:loop_plus 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}

{/loop_area}
{/exp:weblog:entries}
{/exp:loop_plus}

This way there is no performance loss since exp:weblog:entries is initiated only once.

You can even use several {loop_area}{/loop_area} variable pairs inside one {exp:loop_plus} tag.

Conditionals are supported.

       
Ben @PutYourLightsOn's avatar
Ben @PutYourLightsOn
295 posts
16 years ago
Ben @PutYourLightsOn's avatar Ben @PutYourLightsOn

great addition to my plugin, thanks for posting this!

       
Laisvunas's avatar
Laisvunas
879 posts
16 years ago
Laisvunas's avatar Laisvunas

Hi,

I released version 1.3 of Loop Plus plugin.

New features:

1) support for multiple {loop_area}{/loop_area} variable pairs inside one exp:loop_plus tag;

2) support for conditionals.

       
Interfacer's avatar
Interfacer
92 posts
about 16 years ago
Interfacer's avatar Interfacer

Hi Laisvunas

would it be possible to loop the following EE code

{exp:weblog:entries weblog="web_projects" category="11"} 
{exp:weblog:categories weblog="web_projects" style="linear "show="11"}
{category_name}
{title}
{/exp:weblog:categories}
{/exp:weblog:entries}

I want achieve a dynamic list that displays all entries from all categories from a specific weblog (maybe there is another way out there). There is the {wiki:categories} tag that does exactly what I need, but that is only working for wiki templates? http://expressionengine.com/docs/modules/wiki/wiki_templates_special_categories.html#wiki_tag_categories Thanks

       
Laisvunas's avatar
Laisvunas
879 posts
about 16 years ago
Laisvunas's avatar Laisvunas

Hi Interfacer,

It seems that you can achieve what you need using either Weblog Categories Tag or Weblog Category Archive Tag.

       
Matt Weinberg's avatar
Matt Weinberg
489 posts
15 years ago
Matt Weinberg's avatar Matt Weinberg

This seems perfect for what I was looking for. Thanks Laisvunas!

       
daulex's avatar
daulex
152 posts
15 years ago
daulex's avatar daulex

I want this for 2.0 :(

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.