Aternating row content

3 posts by 2 authors in: Forums > CMS Builder
Last Post: October 14, 2015   (RSS)

Hi,

I want to generate content for alternating rows with each odd row having a different layout to even rows. Is there a short cut to achieving this in CMSB 2.14? viz:

Row 1:

  • Col1 = text
  • Col2 = image

Row 2

  • Col 1 = image
  • Col 2 = text

And this sequence carries on to the end.

Attached is a visual of what I want to achieve

Thanks

Terry

Attachments:

altrowscontent.docx 12K

By Damon - October 14, 2015

Hi,

Here is some example code that you can use to get the different layouts for each row. Modify as needed:

<?php $counter = 1; ?>
<?php foreach ($newsRecords as $record): ?>
<?php if($counter % 2) : ?>   
 <!-- ROW 1 -->   
 <?php foreach ($record['image'] as $index => $upload): ?>   
 <img src="<?php echo htmlencode($upload['thumbUrlPath']) ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" alt="" align="left" />   
 <?php break; // show only one image ?>   
 <?php endforeach; ?>   
 <?php echo htmlencode($record['title']) ?><br/>   
 <br clear="left" />
<?php else : ?>
 <!-- ROW 2 -->  
 <?php foreach ($record['image'] as $index => $upload): ?>   
 <img src="<?php echo htmlencode($upload['thumbUrlPath']) ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" alt="" align="right" />   
 <?php break; // show only one image ?>   
 <?php endforeach; ?>   
 <?php echo htmlencode($record['title']) ?><br/>   
 <br clear="all" />
<?php endif; ?>       
 <?php $counter++; ?>
<?php endforeach ?>

Cheers,
Damon Edis - interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/