How to combining 'iF True' string together with current document string ?

Dcode warner asked on June 21, 2017 20:04

  1. How can I combine these two scripts together into one? Basically I'm trying to adding a class if checkbox is True to the existing script:

Existing:

<a href="#" <%# IsCurrentDocument()?"class='selected'":"" %>><%# Eval("DocumentName") %></a>

New update:

<%# ((Eval("showMobileOnly").ToString() == "True") ? "class=\"mobile\"" : "") %>

  1. Additionally. Can I use the new combination script in a 'separator transformation'?: <li <%# IsCurrentDocument()?" class='selected'":"" %> >

I get this message when I attempt to: Message: [CMSAbstractTransformation.DataBind]: Object reference not set to an instance of an object. Stack Trace: Object reference not set to an instance of an object. at ASP.cmsvirtualfiles_transformations__vg_6af8409a_949e_4459_ba54_63873b287840_monarchbeachresortcom0092_sub_seperator_ascx.__DataBind__control2(Object sender, EventArgs e) at System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) at System.Web.UI.Control.DataBindChildren() at System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) at CMS.Controls.CMSAbstractTransformation.DataBind()

Correct Answer

Brenden Kehren answered on June 21, 2017 20:08

I'd do something like this:

class="<%# If(Eval<bool>("ShowMobileOnly"), "mobile ", "") %><%# If(IsCurrentDocument(), "selected", "") %>"

0 votesVote for this answer Unmark Correct answer

Recent Answers


Dcode warner answered on June 21, 2017 21:01

This works. But only the the item transformation. Not the Separator for some reason. It doesn't error anymore but all is returned is <li class="" >

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on June 21, 2017 21:05

The separator is not a binding template which is why it doesn't work. There is no dataview or dataitem with a separator. I'd suggest adding some logic into your transformation if you want to get even/odd levels or just add it always to the end of the transformation and do some checking to see if it is the last one i.e.: DataItemIndex == (DataItemCount - 1) or IsLast()

0 votesVote for this answer Mark as a Correct answer

Dcode warner answered on June 21, 2017 21:09

I understand now. Thank you.

0 votesVote for this answer Mark as a Correct answer

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