5.7 page attribute
Permalink 2 users found helpful
I building a website where I would like to make page lists with thumbnail. This all fine, but I would like that set up several thumbnails for a page and when calling the page list display a certain thumbnail according to a checked attribute.
This was working perfectly in 5.6.X, but in 5.7 it give me an error like: "An unexpected error occured. File does not exist."
I figured out that I have to put all the thumbs attribute for each page on the list, no matter if has the boolean attribute or not, to avoid the error. I would like to set the thumbnails just where I need it not on every page.
Here is my code that worked well previously:
This was working perfectly in 5.6.X, but in 5.7 it give me an error like: "An unexpected error occured. File does not exist."
I figured out that I have to put all the thumbs attribute for each page on the list, no matter if has the boolean attribute or not, to avoid the error. I would like to set the thumbnails just where I need it not on every page.
Here is my code that worked well previously:
<?php defined('C5_EXECUTE') or die("Access Denied."); $th = Loader::helper('text'); $ih = Loader::helper('image'); ?> <?php foreach ($pages as $page): // Prepare data for each page being listed... $title = $th->entities($page->getCollectionName()); $url = $nh->getLinkToCollection($page); $img = $page->getAttribute('webdesignthumb'); $thumb = $ih->getThumbnail($img, 400, 281, true); $category = $page->getCollectionAttributeValue('webdesign'); if ($category) { ?> <article class="project">
Viewing 15 lines of 23 lines. View entire code block.
The exact error is the one I wrote in the post, aka "An unexpected error occured. File does not exist."
Let me clarify a little bit. There is no problem with the file ID. The problem is that the page list controller try to pull thumbnail specified at the "webdesignthumb" attribute for all the pages in the location. But I have this thumbnail set only on pages when also the webdesign boolean attribute is present. And because there are pages without the "webdesignthumb" attribute it give me the above error (off course in some occasion the file does not exist since it wasn't specified).
My problem, or my question is that the code run perfectly on 5.6.x but not on 5.7.x. If you know what was changed in the page list module and how should I modify my code to work again?
Let me clarify a little bit. There is no problem with the file ID. The problem is that the page list controller try to pull thumbnail specified at the "webdesignthumb" attribute for all the pages in the location. But I have this thumbnail set only on pages when also the webdesign boolean attribute is present. And because there are pages without the "webdesignthumb" attribute it give me the above error (off course in some occasion the file does not exist since it wasn't specified).
My problem, or my question is that the code run perfectly on 5.6.x but not on 5.7.x. If you know what was changed in the page list module and how should I modify my code to work again?
I tried your suggestion and still got an error, different this time :)
The error is: An unexpected error occurred.
syntax error, unexpected '{'
I see your point, but still, the problem wasn't with the fileID. For example if I set the thumbnail "webdesignthumb" on every page the page list block is working fine. But this is not productive, since I will have 10 different thumbnail attributes and setting them on each page, regarding that I need it or not, is pointless.
The error is: An unexpected error occurred.
syntax error, unexpected '{'
I see your point, but still, the problem wasn't with the fileID. For example if I set the thumbnail "webdesignthumb" on every page the page list block is working fine. But this is not productive, since I will have 10 different thumbnail attributes and setting them on each page, regarding that I need it or not, is pointless.
I think I understand what you are saying, would it work right if you did this:
$category = $page->getCollectionAttributeValue('webdesign'); if ($category) { $img = $page->getAttribute('webdesignthumb'); ?> <article class="project"> <a href="<?php echo $url ?>" title="<?php echo $title ?>"> <?php if($img){ $thumb = $ih->getThumbnail($img, 400, 281, true); ?> <div class="thumb"> <img src="<?php echo $thumb->src ?>" alt="" width="<?php echo $thumb->width ?>" height="<?php echo $thumb->height ?>" /> </div> <?php } ?> <h2 class="project-title"><?php echo $title ?></h2>
Viewing 15 lines of 18 lines. View entire code block.
I figured out finally. Actually you where right about the fileID, and I can filter the page list without the other attribute (the boolean one). So the correct code is like this:
You missed a ')' first time, this is why it was giving the syntax error.
<?php foreach ($pages as $page): // Prepare data for each page being listed... $title = $th->entities($page->getCollectionName()); $url = $nh->getLinkToCollection($page); $fileID = $page->getAttribute('webdesignthumb'); if(intval($fileID > 0)){ $img = File::getByID($fileID); $thumb = $ih->getThumbnail($img, 400, 281, true); ?> <article class="project"> <a href="<?php echo $url ?>" title="<?php echo $title ?>"> <div class="thumb"> <img src="<?php echo $thumb->src ?>" alt="" width="<?php echo $thumb->width ?>" height="<?php echo $thumb->height ?>" /> </div> <h2 class="project-title"><?php echo $title ?></h2>
Viewing 15 lines of 18 lines. View entire code block.
You missed a ')' first time, this is why it was giving the syntax error.
Oh, and thank you for your support and time. Much appreciated.
I believe that
returns the fileID not an actual file object, so you would need to do