Peter Knight Posted August 18, 2014 Posted August 18, 2014 Can someone sanity check this for me? I have a field called "Featured_Image" and a crop setting called "thumbnail". To outout this thumbnail image, I am trying the following code: <img src={$featured->Featured_Image->first()->getThumb('thumbnail')} /> Currently it's throwing an error and I'm not sure if it means either My module isn't installed properly I'm calling the image incorrectly etc Error: Call to a member function getThumb() on a non-object (line 9 of /Users/mymac/Sites/SiteDev/site/templates/includes/get-featured.inc)
horst Posted August 18, 2014 Posted August 18, 2014 if $featured->Featured_Image->first() isn't an object that has a method getThumb, so what is it actually? or lets have a look at one step before: what does $featured->Featured_Image hold? (an images array, a single image, nothing?)
Peter Knight Posted August 18, 2014 Author Posted August 18, 2014 Hi Horst My field called Featured_Image is an image field as link below. It has field type seto to CropImage http://modules.processwire.com/modules/fieldtype-crop-image/ Currently it just has a single image within it,
horst Posted August 18, 2014 Posted August 18, 2014 but if it has a single image in it, why do you try to select the ->first() ? I assume you have set the image field to allow only 1 image? Also, if you have set it proper to a single image field, it could be that you have a page without an uploaded image to that field. if($featured->Featured_Image) { echo "<img src=\"{$featured->Featured_Image->getThumb('thumbnail')}\" />"; } ------ Also my questions a post above was thought a bit different. I was trying to get you debug the output in your page, just above the line that raises the error. But I wasn't clear, so it doesn't . The error messages said that it isn't an object or the wrong object, so you can debug it to see what's going on. You expect it to be a cropimage field, therefore it should be an instance of type "FieldtypeCropImage". if($featured->Featured_Image->first() instanceof FieldtypeCropImage) { echo "\n<p>the Featured_Image->first() is a cropimage</p>\n"; } if($featured->Featured_Image instanceof FieldtypeCropImage) { echo "\n<p>the Featured_Image is a cropimage</p>\n"; } // imagefield is: FieldtypeImage Most collections in PW are based on WireArrays, so multiple images fields are too and you can look for that: // or checking for single vs multiple if($featured->Featured_Image instanceof WireArray) { echo "\n<p>it is multiple</p>\n"; } else { echo "\n<p>it is single</p>\n"; } You can also just dump a variable with var_dump($featured->Featured_Image->first()) to see what is in it, but that's mostly not very usefull in PW because objects in PW have way to many references to other objects so that var_dump results into very, very large outputs. 5
Peter Knight Posted August 18, 2014 Author Posted August 18, 2014 Cheers Horst. I'll get a chance to try again tomorrow. Appreciate the help. 1
Peter Knight Posted August 21, 2014 Author Posted August 21, 2014 Horst - finally got this to work. Updated the original thread here https://processwire.com/talk/topic/7270-3-cols-of-featured-content-best-practice/
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now