Jump to content

Recommended Posts

Posted

Hi there,

Newbie question: I would like to choose and link to an internal page within repeater items. I have created a repeater with an image and Page Reference field called front_repeater. Page Reference field value type is set to 'Single page'. How can I show the Page Reference title and link on a repeater? Here's what I tried so far.

  <?php if(count($page->front_repeater)) {
  foreach($page->front_repeater->find("limit=10") as $item) {
    $front_img_800 = $item->front_img_800->size(800,0,);
      echo "<img src='$front_img_800->url'>";
      echo "<a href='$item->front_productpage->url'";
      echo "<h2>$item->front_productpage->title</h2>";
      }
    }

Unfortunately it still shows:

1022->title
1023->title

I really appreciate any reply.

Posted

You need to enclose the api vars with curly brackets if there is more than one arrow in it.

echo "<img src='$front_img_800->url'>"; // good
echo "<h2>$item->front_productpage->title</h2>"; // bad
echo "<h2>{$item->front_productpage->title}</h2>"; // good

Read more:
https://processwire.com/talk/topic/4439-when-do-we-need-curly-brackets/
https://www.php.net/manual/de/language.types.string.php#language.types.string.parsing.complex

  • Like 3
  • Thanks 1
Posted

@kixe, Thank you for pointing me in the right direction. As a PW newbie the PHP resource is exactly I was looking for.

PW's Page Reference is so beautiful implemented. Now I can easily select any internal page in a repeater item. Front images show up just fine with a headline and linked to the corresponding internal page. Perfect. Thanks!

echo "<a href='{$item->front_productpage->url}'><img src='{$front_img_800->url}'></a>";
echo "<h2><a href='{$item->front_productpage->url}'>{$item->front_productpage->title}</a></h2>";

 

  • Like 1

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
  • Recently Browsing   0 members

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