Jump to content

Repeater Matrix render on type of repeater


elabx
 Share

Recommended Posts

I want to render a repeater matrix repeater type with the following code:

foreach($page->content_repeater_matrix as $content){
    if($content->type == "hero"){
      $content->render();
      break;
    }
  }

The field has its own field template asigned in fields/content_repeater_matrix/hero.php.

Why shouldn't this work? It would seem to me to be "the processwire way" :D

I got this one working in fields/content_repeater_matrix.php:

<?php
foreach($value as $item) {
  echo $item->render();
}

Am I trying to call render in the wrong context?

Link to comment
Share on other sites

4 hours ago, elabx said:

Why shouldn't this work? It would seem to me to be "the processwire way"

Not only "the processwire way", but also the way that is demonstrated in the documentation:

foreach($page->test_matrix as $item) {
  if($item->type == 'blockquote') {
    echo "
      <blockquote>
         <p>$item->quote</p>
         <cite>$item->quote_cite</cite>
      </blockquote>
      ";
  } else if($item->type == 'bodycopy') {
    echo "
      <h2>$item->title</h2>
      $item->body
      ";
  } else if($item->type == 'gallery') {
    // and so on...
  }
}

 

Link to comment
Share on other sites

2 hours ago, kixe said:

maybe just a missing echo?


foreach($page->content_repeater_matrix as $content){
  if($content->type == "hero"){
    echo $content->render();
    break;
  }
}

 

Guess I just jumped to fast on the forum, thanks!

  • Like 1
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...