Break block1.block2 in template or adapting assign_block_vars?

Need some custom code changes to the phpBB core simple enough that you feel doesn't require an extension? Then post your request here so that community members can provide some assistance.

NOTE: NO OFFICIAL SUPPORT IS PROVIDED IN THIS SUB-FORUM
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

NOTE: NO OFFICIAL SUPPORT IS PROVIDED IN THIS SUB-FORUM
Post Reply
RobiX
Registered User
Posts: 110
Joined: Thu Oct 05, 2017 9:59 am

Break block1.block2 in template or adapting assign_block_vars?

Post by RobiX »

Code: Select all

for ($i = 0; $i < 6; $i++) {
  for ($j = 0; $j < 6; $j++) {
    for ($k = 0; $k < 6; $k++) {
      $var1 = $i + $k + $j;
      $var2 = $i * $k * $j;
    }
    $template->assign_block_vars('block1.block2', array( 'ITEM0' => $var1, 'ITEM1' => $var2 ));
  }
}

Code: Select all

<!-- BEGIN block1 -->
<tr>
<!-- BEGIN block2 -->
<td>
  {block1.block2.ITEM0}</a>
</td>
  <!-- END block2 -->
</tr>
<!-- END block1 -->
currently: the whole table looks like this:

Code: Select all

<tr><td></td></tr>
my wish: Is it possible to break the block2 after, e.g., 6 iterations - so it can look like this:

Code: Select all

<tr><td></td><td></td><td></td><td></td><td></td><td></td></tr>
I think there are two possibilities - adapting php-file (block1.block2?!) or template (break in begin block2 possible?).
But none of them I could do :(.
User avatar
Brf
Support Team Member
Support Team Member
Posts: 53413
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}
Contact:

Re: Break block1.block2 in template or adapting assign_block_vars?

Post by Brf »

If your "block1" is the rows and the "block2" is the columns, then you are writing all of your columns in the same row.
If you want separate rows, you need to write $template->assign_block_vars('block1', ... at the beginning of each row.
User avatar
kasimi
Former Team Member
Posts: 4900
Joined: Sat Sep 10, 2011 7:12 pm
Location: Germany
Contact:

Re: Break block1.block2 in template or adapting assign_block_vars?

Post by kasimi »

Also have a look at Twig's batch filter: https://twig.symfony.com/doc/2.x/filters/batch.html
RobiX
Registered User
Posts: 110
Joined: Thu Oct 05, 2017 9:59 am

Re: Break block1.block2 in template or adapting assign_block_vars?

Post by RobiX »

@brf: tnx it works now - cool + tnx :)

@kasimi: i always read twig but never searched for it - i will do it! :) tnx for you help
Post Reply

Return to “phpBB Custom Coding”