Macros

Sherry Collins asked on May 15, 2015 19:37

I need to modify a transformation that has this statement:

<%# IfEmpty(Eval("NewsTeaser"), "", GetImage("NewsTeaser")) %>

This is getting a blank image which I don't want. I don't want it to get anything.

How would I change this macro to return nothing.

Thanks in advance.

Correct Answer

Petar Kozjak answered on May 18, 2015 11:00

Hi,

we use different code for getting image: <%# IfEmpty(Eval("NewsTeaser"), "", "<div class'image'><img src='" + GetFileUrl("NewsTeaser") + "' alt='" + Eval("NewsTitle") + "' /></div>" /> %>

As you can see in here I have wrapped also div code. So if image is empty no div will show.

What version of Kentico are you using. Try code <%# Eval("NewsTeaser") %> just to see does it return something or nothing. I know in older version it would return 0000-000-000 and that is not empty so this code wont work.

0 votesVote for this answer Unmark Correct answer

Recent Answers


Charles Matvchuk answered on May 15, 2015 20:17

What is the rest of your transformation code? That should return nothing, unless it is wrapped or part of something more. That Macro resolves to I believe an tag.

0 votesVote for this answer Mark as a Correct answer

Rui Wang answered on May 15, 2015 20:22

Sherry, are you using the NewsDetail transformation for the News page type? If you don't want the image to be display, simply remove that line.

<div class="newsItemDetail">
    <h1><%# Eval("NewsTitle",true) %></h1>
    <div class="NewsSummary">
      <div class="NewsContent">
        <div class="Date"><%# GetDateTime("NewsReleaseDate", "d") %></div>
        <div class="TextContent"><%# Eval("NewsSummary") %></div>
      </div>
      <div class="Clearer">&nbsp;</div>
    </div>
    <div class="NewsBody">
      <div class="TextContent"><%# Eval("NewsText") %></div>
    </div>
    </div>
0 votesVote for this answer Mark as a Correct answer

Charles Matvchuk answered on May 15, 2015 20:26

If I recall correctly the class for that line shows the blank image.

0 votesVote for this answer Mark as a Correct answer

Sherry Collins answered on May 15, 2015 20:26

Rui/Charles

I am using the NewsWithSummaryAndTeasers Transformation

<%# IfEmpty(Eval("NewsTeaser"), "", GetImage("NewsTeaser")) %>
<%# GetDateTime("NewsReleaseDate", "d") %>
<%# Eval("NewsSummary") %>

I want the image, if its not empty, but I don't want the default teaser image if its empty.

0 votesVote for this answer Mark as a Correct answer

Charles Matvchuk answered on May 15, 2015 20:27

Check the CSS Class.

0 votesVote for this answer Mark as a Correct answer

Sherry Collins answered on May 15, 2015 21:00

Charles

I don't think you understand the problem. I do not want the blank image to show if there is no real image uploaded. I need to collapse the Teaser

and just show the summary text left justified.

0 votesVote for this answer Mark as a Correct answer

Rui Wang answered on May 15, 2015 21:59 (last edited on May 15, 2015 22:12)

Sherry, but that <%# IfEmpty(Eval("NewsTeaser"), "", GetImage("NewsTeaser")) %> should be doing what you are looking for,

That says if "NewsTeaser" is empty, then return "" (nothing), otherwise, return GetImage("NewsTeaser").

Can you check in your news article page, under the FORM tab, the teaser button is showing with anything selected?

0 votesVote for this answer Mark as a Correct answer

Charles Matvchuk answered on May 15, 2015 23:19

Sherry, I looked at my production code and it does collapse and not show anything when the IfEmpty is resolved. There must be something else.

0 votesVote for this answer Mark as a Correct answer

Sherry Collins answered on May 16, 2015 15:40

Rui

I am looking at the form tab in the news article page and there is no image selected, as expected. However on the actual home page it is showing the empty photo image that you would normally see when there is no picture. For example, look at my post. I don't have an image uploaded so it shows the default image. That is the same thing that is happening in my website. For my posts, how would I collapse the div where the blank photo is and move all the text to the left.

If the macro in the transformation is collapsing the div then I am at a loss as to where else to look.

0 votesVote for this answer Mark as a Correct answer

Charles Matvchuk answered on May 16, 2015 16:02

The div is not collapsed by the Macro. The Macro returns nothing so nothing is put in the div. That is why I asked you to post your complete code. the code you have above has no div's and no classes. Is there a class on the div ? If so what is the class indicating in the CSS.

0 votesVote for this answer Mark as a Correct answer

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