Accessing Boolean document field in k#

Nathan Tritt asked on August 11, 2014 17:53

I am having some trouble with some K# syntax within a transformation.

I have a document type that has a Boolean check box field. I want to be able to use this field in a conditional statement to decide a class name.

currently I have:

<li class="{% Eval("isFeatured").toLower() == "true" ? "isFeatured" : "" %}">

the part that is seeming to not work is the area between {% %}. it is rendering out in the DOM as:

<li class="{% Eval(" isfeatured").tolower()="=" "true"="" ?="" "isfeatured"="" :="" ""="" |(user)administrator|(hash)498f3f53b6cf5d97668230efbdd569fc51cdf3702d5e097e37e0de0867f3faf1%}"="">

I would like the

  • tag to render as either
  • or
  • .

    any help on this would be appreciated.

    thanks in advance.

  • Recent Answers


    Nathan Tritt answered on August 11, 2014 17:54

    the li tags should render with a class name of either "isFeatured" or ""

    sorry the editor took my tags and markup.

    0 votesVote for this answer Mark as a Correct answer

    Brenden Kehren answered on August 11, 2014 18:46

    Are you using ASCX transformation or some other text type of transformation? If its not ASCX, then Eval("ColumnName") will not work. I believe you have to use GetValue("ColumnName").ToBool() for the text transformations although I don't use them very often if at all.

    0 votesVote for this answer Mark as a Correct answer

    Jim Spillane answered on August 11, 2014 18:51

    As Brenden said no Eval() needed in Text/XML. You can do the test on a bool like:

    {%isFeatured == true ? "isFeatured" : ""%}

    2 votesVote for this answer Mark as a Correct answer

    Nathan Tritt answered on August 11, 2014 19:18

    I was using the ASCX.

    what would be the best practice to do this type of conditional operation?

    0 votesVote for this answer Mark as a Correct answer

    Nathan Tritt answered on August 11, 2014 19:36

    I found a reference guide that showed me methods that could be used. here is the link.

    I also switched my code to <li class="<%# IfTrue(Eval("isFeatured"), "featured")%>"> this worked for me

    0 votesVote for this answer Mark as a Correct answer

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