Custom template Express List?
Permalink
Hi C5'ers!
I'm getting into the new express, really love it!!
I'm trying to display an express list with a custom template, but how do I output my custom attribute values individually, instead of displaying all values of the item? Is there something just like the getBoats method on Andrew's example? Below stripped list template:
Many thanks,
Nick
I'm getting into the new express, really love it!!
I'm trying to display an express list with a custom template, but how do I output my custom attribute values individually, instead of displaying all values of the item? Is there something just like the getBoats method on Andrew's example? Below stripped list template:
<?php defined('C5_EXECUTE') or die(_("Access Denied.")); $c = Page::getCurrentPage(); if ($entity) { $results = $result->getItemListObject()->getResults(); if (count($results)) { foreach($result->getItems() as $item) { foreach($item->getColumns() as $column) { // echo $column->getColumnValue($item); // How do I echo attribute name? getMyAttributeHandle? // How do I echo attribute image? } } } else { echo t('No "%s" entries can be found', $entity->getName()); }
Viewing 15 lines of 17 lines. View entire code block.
Many thanks,
Nick
Inside the loop of $result->getItems() as $item you can use the getEntry() on the $item and store that to a variable to use the get[AttributeName]() on the variable.
The get[AttributeName]() ? Could you elaborate that?
Nevermind, got it: $blah->getSurname() and so on.
Nevermind, got it: $blah->getSurname() and so on.
How do I do this with an image that is stored in the file manager? If I use the code you suggested I get this error: "Object of class DoctrineProxies\__CG__\Concrete\Core\Entity\File\File could not be converted to string"
<?php echo $item->getEntry()->getProductImage(); ?>
I figured this out.
<?php echo $item->getEntry()->getProductImage()->getUrl(); ?>
You can also resize the image:
$productThumbnail = $item->getEntry()->getProductImage(); if ($productThumbnail) { if ($productThumbnail_thumb = Core::make('helper/image')->getThumbnail($productThumbnail, 250, 250, true)) { // square 250x250, cropped $imgsrc = $productThumbnail_thumb->src; } } echo '<img src="' . $imgsrc . '">';
Any insights on how would you call the Associated Object in the same list?