Custom attribute
Permalink Browser Info Environment
Hello,
I'd like to add an image to the menu, which is a custom attribute 'thumb' of each page. I'v tried several things, but I can't get it in the foreach loop. Any ideas?
Big thnx!
-- edit ! --
Nevermind, I found it! See code below if you're interested!
Regards,
Nick
in controller.php:
foreach list item in in view.php:
I'd like to add an image to the menu, which is a custom attribute 'thumb' of each page. I'v tried several things, but I can't get it in the foreach loop. Any ideas?
Big thnx!
-- edit ! --
Nevermind, I found it! See code below if you're interested!
Regards,
Nick
in controller.php:
function view() { $nh = Loader::helper('navigation'); $ih = Loader::helper('image'); $linkRows = $this->getLinks(); $linkObjs = array(); foreach ($linkRows as $row) { $page = Page::getByID($row['linkToCID']); $link = new stdClass; $link->url = $nh->getLinkToCollection($page); $link->text = $row['linkText']; $link->cID = $row['linkToCID']; $link->cPath = $page->getCollectionPath(); // get some page attributes $img = $page->getAttribute('thumbnail'); // thumbnail is a page attribute image $thumb = $ih->getThumbnail($img, 244, 9999, false); // i always want the same width
Viewing 15 lines of 22 lines. View entire code block.
foreach list item in in view.php:
<?php foreach ($links as $link): $thumb = $link->myThumbnail->src; // thumbnail $cssClasses = array(); if ($currentCID == $link->cID) { $cssClasses[] = 'nav-selected'; } if (strpos($currentCPath, $link->cPath) === 0) { $cssClasses[] = 'nav-path-selected'; } $cssClasses = implode(' ', $cssClasses); ?> <li class="<?php echo $cssClasses; ?>"> <h3><a href="<?php echo $link->url; ?>" class="<?php echo $cssClasses; ?>"><?php echo htmlentities($link->text, ENT_QUOTES, APP_CHARSET); ?></a></h3> <a href="<?php echo $link->url; ?>"><img src="<?php echo $thumb; ?>" width="<?php echo $link->myThumbnail->width ?>" height="<?php echo $link->myThumbnail->height ?>" alt="<?php echo htmlentities($link->text, ENT_QUOTES, APP_CHARSET); ?>" border="0" /></a> <p><?php echo htmlentities($link->myDescription, ENT_QUOTES, APP_CHARSET); ?></p>
Viewing 15 lines of 17 lines. View entire code block.
Type: | Discussion |
---|---|
Status: | New |