BlogPostTeaser Image Not Showing Up

Andre Pfanz asked on March 18, 2016 19:08

I'm pretty new to Kentico.

I'm using Kentico 9.0 and am having a problem with displaying the Blog Post Teaser field. I'm uploading images for the teaser and using this transformation:

{% IfEmpty(Eval("BlogPostTeaser"), "", "<img src=\"" + GetFileUrl("BlogPostTeaser") + "\" />") %}

However, I get this as the output:

<img src="">

Any ideas what I'm doing wrong?

Correct Answer

Trevor Fayas answered on March 18, 2016 19:29

I know there's a GetFileUrl in the ASCX transformation methods, but i don't believe there is anything like that in the macro syntax.

So for a quick fix, switch your transformation type to ASCX and put this:

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

Here's some additional reading:

https://docs.kentico.com/display/K9/Writing+transformations

https://docs.kentico.com/display/K9/Reference+-+Transformation+methods (For ASCX Transformations)

https://docs.kentico.com/display/K9/Reference+-+Macro+methods#Reference-Macromethods-Transformations (For Text/XML)

0 votesVote for this answer Unmark Correct answer

Recent Answers


Chetan Sharma answered on March 18, 2016 21:58 (last edited on March 18, 2016 21:59)

Assuming you are using Kentico BlogPost and you are using contribution form to fill this value of BlogPostTeaser

How about using this?

{% IfEmpty(Eval("BlogPostTeaser"), "", "<img src=\"" + Eval("BlogPostTeaser") + "\" />") %}

or

{% If(Eval("BlogPostTeaser"), "<img src=\"" + Eval("BlogPostTeaser") + "\" />", "") %}

I also recommend the solution suggested by Treveor.

Thanks, Chetan

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on March 18, 2016 22:26

As both Trevor and Chetan have provided solutions, the actual problem is the GetFileUrl() method actually takes in a GUID and not a string. So when you write GetFileUrl("BlogPostTeaser") it's evaluating "BlogPostTeaser" as a GUID and failing. When you write GetFileUrl(Eval("BlogPostTeaser")) it will evaluate the BlogPostTeaser column value being returned in the data view.

4 votesVote for this answer Mark as a Correct answer

Andre Pfanz answered on March 21, 2016 18:04

Thanks guys.

0 votesVote for this answer Mark as a Correct answer

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