GetImage

Deann Graham asked on September 22, 2015 23:00

Where would I find the original code for GetImage tranformation. I am trying to create a custom transformation that will allow me to assign a class.

Correct Answer

Maarten van den Hooven answered on September 22, 2015 23:57

Hi Dean, Sorry there was a small mistake in the code, try this:

<%# IfEmpty(Eval("BlogPostTeaser"), "", "<img class=\"classname\" src=\"" + GetFileUrl("BlogPostTeaser") + "\" />") %>

0 votesVote for this answer Unmark Correct answer

Recent Answers


Brenden Kehren answered on September 22, 2015 23:11

The GetImage() method is compiled and part of the Kentico DLLs. You might look into changing your method use and/or use a different field for the image where you can use a URL vs. having it create your full <img> tag for you.

0 votesVote for this answer Mark as a Correct answer

Maarten van den Hooven answered on September 22, 2015 23:12 (last edited on September 22, 2015 23:21)

Dear Deann,

I cannot give the orginal Kentico code for the GetImage method, but what do you need to do?

If you only want to add an css class to an image you can also do this in your transformation with standard Kentico:

<img class="CLassName" src="<%# GetFileUrl("NameColumnOfYourImage") %>" />

Another example with an news teaser image:

<%# IfEmpty(Eval("NewsTeaser"), "", "<img class="CLassName" alt=\"" + Eval("NewsTitle") + "\" src=\"" + GetFileUrl("NewsTeaser") + "?maxsidesize=100\" />

Good luck and if you want to do something else or more please let us known, probably we can help you further.

If this answer helped you, please vote for my answer :-)

0 votesVote for this answer Mark as a Correct answer

Deann Graham answered on September 22, 2015 23:20

In the use of blogs, You can return the featured image, but cannot add a class to the image in recent posts web part and The transformation is: <%# GetImage("BlogPostTeaser") %> want to add classes to it. can't

<%# Eval("BlogPostTitle", true) %>

<%# Eval("BlogPostBody") %>

0 votesVote for this answer Mark as a Correct answer

Deann Graham answered on September 22, 2015 23:22

Found the only solution is creating a custom transformation, which I can, just need to know what I am adding, so if I know what the current method looks like I could create it.

0 votesVote for this answer Mark as a Correct answer

Maarten van den Hooven answered on September 22, 2015 23:26 (last edited on September 22, 2015 23:58)

Hi Dean, so if you change your transformation to:

<%# IfEmpty(Eval("BlogPostTeaser"), "", "<img class=\"ClassName\" alt=\"\"" + Eval("BlogPostTitle") + "\" src=\"" + GetFileUrl("BlogPostTeaser") + "\" />") %>

Is this working for you?

If this answer helped you, please vote for my answer :-)

1 votesVote for this answer Mark as a Correct answer

Deann Graham answered on September 22, 2015 23:48

[TempITemplate.Template]: http://server/Kentico82/CMSVirtualFiles/Transformations/=vg=456b4f20-602f-41b5-b984-71b36079557c/CMS.Blog/Description.ascx(3): error CS1010: Newline in constant

0 votesVote for this answer Mark as a Correct answer

Deann Graham answered on September 22, 2015 23:48

Something is wrong with the quotes

0 votesVote for this answer Mark as a Correct answer

Deann Graham answered on September 23, 2015 00:07

Not quite.. This worked <%# IfEmpty(Eval("BlogPostTeaser"), "", "<img class=\"col-md-5 img-responsive pull-left\" src=\"" + GetFileUrl("BlogPostTeaser") + "\" />") %>

The alt part exported each word of the post title like="" This="" So I took it out for now. Many many thanks.

0 votesVote for this answer Mark as a Correct answer

Maarten van den Hooven answered on September 23, 2015 00:11 (last edited on September 23, 2015 00:11)

Hi Dean, Great thanks and off course your welcome. Good luck with further developing!!!!

0 votesVote for this answer Mark as a Correct answer

Dennis Hulsmans answered on March 23, 2016 13:56 (last edited on March 23, 2016 13:58)

Hi Maarten

I noticed that when you remove the file extensions from the settings.. the image will not render. You'll get something like this:<img class="news__image" src="/getattachment/43955191-ffd4-435b-b60a-a47864cdfe1b/"> . This will result in a broken image, unless you add some text after the last / . Any idea what's wrong? I have a simular topic on this http://devnet.kentico.com/questions/kentico-9-getimage. But it's a strange thing which I'm having over and over again.

1 votesVote for this answer Mark as a Correct answer

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