[Beginner] Blocks and HTML structure question

Permalink
Say I have an HTML structure similar to the code below, how would I setup the block so I could control the opening and closing .row divs?

I'm thinking that each .item would be a block and then trying to find a way to have a counter or something so I could place the opening and closing .row divs based on how many items are being displayed. Is this possible? Or should each row be a block instead of each item?

I know that I could probably edit the HTML to remove the .row divs, but humor me because I'm interested in the answers to this question with the current HTML in place.

Thank you!

<div class="row">
  <div class="item"><!-- data --></div>
  <div class="item"><!-- data --></div>
  <div class="item"><!-- data --></div>
</div>
<div class="row">
  <div class="item"><!-- data --></div>
  <div class="item"><!-- data --></div>
  <div class="item"><!-- data --></div>
</div>
<div class="row">
  <div class="item"><!-- data --></div>
  <div class="item"><!-- data --></div>
  <div class="item"><!-- data --></div>
</div>

 
MrKDilkington replied on at Permalink Reply
MrKDilkington
Hi ericmobley34,

I am not positive, but this might put you on the right track.

<div class="row">
<?php 
   $a = new Area('Your Area Name');
   $a->setBlockWrapperStart('<div class="item">');
   $a->setBlockWrapperEnd('</div>');
   $a->display($c); 
?>
</div>
ericmobley34 replied on at Permalink Reply
That doesn't give me any control over the outermost .row div. My main goal is to figure out how I can make the template so it inserts the opening and closing .row div when appropriate.
jordanlev replied on at Permalink Best Answer Reply
jordanlev
If you have a fixed number of rows/items (and there aren't a huge number of them), your best bet is to just create separate fields for each item and output the markup explicitly. This could be done very easily/quickly with the Designer Content addon (or you can create it yourself for learning purposes, or if you're on 5.7 because DC hasn't been updated yet). For example:
//in your block's view.php file...
<div class="row">
  <div class="item"><?php echo $field1; ?></div>
  <div class="item"><?php echo $field2; ?></div>
  <div class="item"><?php echo $field3; ?></div>
</div>
<div class="row">
  <div class="item"><?php echo $field4; ?></div>
  <div class="item"><?php echo $field5; ?></div>
  <div class="item"><?php echo $field6; ?></div>
</div>
<div class="row">
  <div class="item"><?php echo $field7; ?></div>
  <div class="item"><?php echo $field8; ?></div>
  <div class="item"><?php echo $field9; ?></div>


Or you could make a block for each "row" and have the user add the block multiple times as needed to the area:
//in your block's view.php file...
<div class="row">
  <div class="item"><?php echo $field1; ?></div>
  <div class="item"><?php echo $field2; ?></div>
  <div class="item"><?php echo $field3; ?></div>
</div>


Neither of those is perfect though. Ideally what you want are "repeating items", which can be achieved very easily using the paid "Designer Content Pro" addon:
http://www.concrete5.org/marketplace/addons/designer-content-pro...
(but note that I haven't updated that for 5.7 yet, so for now it only works on 5.6).

-Jordan
ericmobley34 replied on at Permalink Reply
Thanks, Jordan. I was thinking of just doing the second example where each row is a block, but even that doesn't seem intuitive.

I may have to check out the Designer Content Pro add-on. The CMS that I used for 4.5 years allowed me to do a foreach and iterate through each item which allowed me to control the wrapper HTML like the .row divs in my example.
jordanlev replied on at Permalink Reply
jordanlev
What CMS is that? (Just curious, I'm always interested in learning about new systems).
ericmobley34 replied on at Permalink Reply
The CMS that I used for 4.5 years is called the Site Management Console. It's a system that the company that I used to work for made and isn't based on any other system. On that platform I can easily iterate through items and manipulate the HTML based on which iteration it is currently on. Not saying that's better but it's what I'm used to.

To your other comment about C5 in Minneapolis: I have seen some fellow Minneapolis comrades talking up C5, I may have to join them for a meetup sometime.
jordanlev replied on at Permalink Reply
jordanlev
Also, I see that you're in Minneapolis. There's a fairly active C5 community there... if you haven't been to a meetup you should totally go next time -- great group of people!
ericmobley34 replied on at Permalink Reply
I ended up using Designer Content Pro. This does exactly what I want, which was essentially the ability to foreach through items. Thanks!!