showing images

Sherry Collins asked on May 8, 2015 14:45

I am developing a new portal by modifying the intranet portal that comes with kentico. We want to have a news section that will show the last N news articles. If the person who creates the article does not upload a teaser image then they want the text to shift to the left and not show the empty default image. Has anyone every done this or would have information on how to get this done.


Recent Answers

Virgil Carroll answered on May 8, 2015 15:48


The easiest way to do this is to modify the transformation and create the html template to support this. You could do this by using % width in table cells or divs (via css) so that when an image is not present the cell or div collapses. The more clean method is to use CSS floats (to the left) so that when an image is not there the text will float over to the left side. You use this in combination with divs.

I am assuming you are using the default news webpart set-up, which uses some macro code to show the default image placeholder if no image is present. You will need to remove that as well as use a macro to not show anything if the image field value is empty.

Hope that helps.

1 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on May 8, 2015 17:02

To add to Virgil's answer you can also do some checking in the transformation to see if that field has a value or not. If not, then don't do as it is already setup to do and display some default placeholder, just don't display the HTML element(s). Here's an example

<%# IfEmpty(EvalText("SKUImagePath"), "", "<img src='/Site/media/Items/Thumbnails/" + EvalText("SKUImagePath") + "'/>")%>
2 votesVote for this answer Mark as a Correct answer

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