Kentico 9 GetImage

Tobania Kentico asked on December 2, 2015 18:10

Hi

I'm fairly new to Kentico in general. I've followed the essentials which was pretty easy. Now I'm trying to recreate a website in Kentico 9

At this point I noticed something rather strange: In K8 > GetImage renders the image In K9 > GetImage doesn't render the image, but when I add a /abcd (with abcd being anything) it does render the image.

Also I'm trying to get the image as a background image, any advice how this could be achieved? I've tried this several things like: <li style="background: url(<%# GetFileUrl("SliderImage") %>);">

and GetMediaUrl

transformations documentation at: https://docs.kentico.com/display/K9/Reference+-+Transformation+methods#Reference-Transformationmethods-Images

Thx!

KR, Dennis

Correct Answer

Dennis Hulsmans answered on May 13, 2016 12:10

Please note that if you use the columns field to select some columns, you'll have to include NodeAlias. NodeAlias is used by GetImage or GetFileUrl

see K9 documentation on loading data efficiently

1 votesVote for this answer Unmark Correct answer

Recent Answers


Laura Frese answered on December 2, 2015 20:33 (last edited on December 2, 2015 20:39)

Have you tried GetMediaFileURL?
Returns the URL of the specified media file. The media file is specified by the file GUID in the first parameter and the file name in the second parameter.
<%# GetMediaFileUrl(Eval("FileGUID"), Eval("FileName")) %>

You could also try <li style="background:url(/CMSPages/GetFile.aspx?guid=<% Eval("SliderImage")%>)">

1 votesVote for this answer Mark as a Correct answer

Tobania Kentico answered on December 2, 2015 21:24

Hi Laura

I've tried several things, GetMediaFileUrl being one of them. I'm not sure what's going wrong. I'm going to recreate my page type and try it again. In K8 it everything went smoothly, K9 isn't.

I'll keep you posted!

0 votesVote for this answer Mark as a Correct answer

Laura Frese answered on December 2, 2015 22:35

What is the data type of the field, what form control are you using to upload the image? If you just show the Data for that field on the page, does it show a GUID?

0 votesVote for this answer Mark as a Correct answer

Dennis Hulsmans answered on December 4, 2015 10:03 (last edited on December 4, 2015 10:51)

Hi Laura

The data type of the field is "File", and I'm using the "upload file" form control. It does show the GUID, because when I add a trailing / with some random text, the image will render.

Not sure what's going wrong here, since I've done the same thing in K8.2 and it was working like it should.

In short: something like this works, mind the + "x" at the end : <li style="background:url(<%# GetFileUrl("SliderImage") + "x" %>)">

It seems that it has something to do with the Files friendly URL extension in K9. I removed the default value (.aspx) to empty. This works fine in K8 but not in K9. Even the example sites won't show images if I remove the .aspx.

In K8 it adds the filename behind the "/", ex: <img src="/SiteName/getattachment/512b1b3c-8f26-493f-a0b0-b0c35174d996/Plane-2?maxsidesize=200" alt="">

1 votesVote for this answer Mark as a Correct answer

Laura Frese answered on December 23, 2015 20:09

What did you set in the settings for URLs and SEO? Did you take a look at the K9 documentation for the settings?

1 votesVote for this answer Mark as a Correct answer

Tobania Kentico answered on January 21, 2016 17:27

found the correct notation: <li style="background:url(<%# GetFileUrl("SliderImage", "DocumentName") %>)">

thx for the help !

1 votesVote for this answer Mark as a Correct answer

Stephen Rushing answered on October 11, 2016 22:52

In v9.0.23, I was using IfImage("FieldName", GetImage("FieldName"), "") method, which seemed to return false for an unpublished page. I updated the transformation to use IfEmpty("FieldName", "", GetImage("FieldName")) instead, and it worked as expected.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.