Jump to content

[SOLVED] Field title value


Martinus
 Share

Recommended Posts

Hello,

I try to display my field value from a page but it only shows: 1020->title

On my product page I use $product->vendor->title and displays just fine: Samsung

My code:

<ul>
  <?php
$items = $pages->find("parent=/products/, limit=3, sort=-date");
foreach($items as $item) {
   echo "<li>" .
        "<h3><a href='$item->url'>$item->title</a></h3>" .
        "<p>$item->vendor->title</p>" .
        "<p>$item->summary</p>" .
        "</li>";
}
?>
</ul>

What I do wrong?

Link to comment
Share on other sites

Enclose the variable parts in curly braces:

"<p>{$item->vendor->title}</p>"

Otherwise it will only evaluate the first property, $item->vendor. Because it’s a page, you get its ID.

It’s bugging me that I can’t seem to find any mention of this limitation in the PHP docs. It only says it will “greedily take as many tokens as possible to form a valid variable name”, but apparently it’s not so greedy with sub-properties? Anyway, I simply always use curly braces…

Btw, if you use an editor with a language server such as PHP Intelephense, the syntax highlighting will show you the problem:

grafik.png.92254c665af5a4e27520568b53ac5191.png

  • Like 1
Link to comment
Share on other sites

  • Martinus changed the title to [SOLVED] Field title value

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...