Transformation If() and IfTrue() Has Negative Result Even When Row Has True (1) Value

kentico guy asked on August 3, 2020 20:22

Context: Kentico 12.0.15 portal engine in an ascx transformation

I am trying to implement a very simple border style to an html tag using transformation methods If() and IfTrue(). The problem is that both methods are acting as if the bool is set to false even when the value in the database is 1. "TeaserHasBorder" is a custom page type field. I have it set to a bool, but it is not set to be "required."

"ArticleImage" is a column in the same table as "TeaserHasBorder," so I know that Kentico should be looking at that same table.

I've tried both of these below:

<article class='featured' style='display:none;'>
  <img src="<%# Eval("ArticleImage") %>" alt="<%# Eval("ArticleFullTitle") %>" style="<%# IfTrue("TeaserHasBorder", "border: black solid;")%>" />
</article>

<article class='featured' style='display:none;'>
  <img src="<%# Eval("ArticleImage") %>" alt="<%# Eval("ArticleFullTitle") %>" style="<%# If(Eval("TeaserHasBorder"), "border: black solid;", "") %>" />
</article>

The problem is that

style="<%# IfTrue("TeaserHasBorder", "border: black solid;")%>"
style="<%# If(Eval("TeaserHasBorder"), "border: black solid;", "")%>"

is returning

style=""

even when the page property "TeaserHasBorder" is set to 1 (true). I have checked in the page tab and in the database and that property is set properly.

Is there something else that I should check? Does the syntax look correct, or did I miss something?

Thanks in advance!

Recent Answers


kentico guy answered on August 3, 2020 22:57 (last edited on August 3, 2020 23:16)

The problem was that this webpart view was not within the context of my custom page type. There is a dependency of page type query in (page type) > Queries which needed to get modified. So if you're having this problem in the future you might want to check your page type queries and make sure you're pulling the new page type field.

More experienced Kentico people can chime in here, but I think this needs to be done when you're using a page type transformation outside of a page of that type, or if the transformation has a page type query dependency.

I know this may not be of much use, but it was what the issue was for me, so posting it just in-case you want something to check.

EDIT: Just a bit of extra information

I was using Universal viewer with custom query webpart and the query that I needed to modify was in the content textbox.

Part of my mistake was assuming that because the "generate default transformation" contained my page type field bool, it would thus be available in the transformation; this was not correct. The data comes from the content query (obvious in hindsight).

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on August 4, 2020 15:00

This is very rudimentary but something as simple as changing from double quotes to single quotes could fix this. I've seen this when setting visibility all the time.

<img src='<%# Eval("ArticleImage") %>' alt='<%# Eval("ArticleFullTitle") %>' style='<%# If(Eval("TeaserHasBorder"), "border: black solid;", "") %>' />

Typically it's not an issue with using simple evaluation statements, it's more of a problem when trying to do anything logical within a property's value.

0 votesVote for this answer Mark as a Correct answer

Michael Eustace answered on August 10, 2020 18:09

Just to add to Brendan's answer, if you are specifying which columns of your page type to return in your repeater/data source, just double check you haven't missed off TeaserHasBorder as that would give you a null value for that field in your transformation.

Of course, if you're not specifying any columns at all then this won't be the issue (as this selects all columns) but it's always good practice to select only the columns of data you need, so as to keep the the underlying SQL query as light and performant as possible.

0 votesVote for this answer Mark as a Correct answer

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