Damienov Posted March 8, 2014 Share Posted March 8, 2014 Is there a way to get the item id from a repeater field? for example: <? foreach($page->items as $item): ?> <div class="classname-<?php echo $item->id; ?>"> <h2><?php echo $item->title; ?></h2> <p><?php echo $item->content; ?></p> </div> <?php endforeach; ?> with an expected output of something like this <div class="classname-1"> <h2>title 01</h2> <p>content</p> </div> <div class="classname-2"> <h2>title 02</h2> <p>content</p> </div> <div class="classname-3"> <h2>title 03</h2> <p>content</p> </div> Link to comment Share on other sites More sharing options...
JeffS Posted March 8, 2014 Share Posted March 8, 2014 Yes, a each repeater has an id so your example would work. Link to comment Share on other sites More sharing options...
adrian Posted March 8, 2014 Share Posted March 8, 2014 As Jeff pointed out, your example should work as coded. However I am thinking from your example that you don't actually want the repeater id, but an auto-incrementing number starting at 1. Is that right? If so, simply define: $i=1 before the foreach starts and then $++ just before the loop closes. Then use the $i instead of $item->id Does that help? 2 Link to comment Share on other sites More sharing options...
Damienov Posted March 8, 2014 Author Share Posted March 8, 2014 As Jeff pointed out, your example should work as coded. However I am thinking from your example that you don't actually want the repeater id, but an auto-incrementing number starting at 1. Is that right? If so, simply define: $i=1 before the foreach starts and then $++ just before the loop closes. Then use the $i instead of $item->id Does that help? yep this works thanks Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now