cms:CMSConditionalLayout visibility

Eagle Y asked on August 19, 2015 17:40

Hi,

I would like to control visibility of a few <cms:CMSConditionalLayout runat="server" id="layout1" >

using value I retrieve from current page type.

I set up custom fields in page type.

I can retrieve these values in page layout but for some reason it does not work.

I tired: <cms:CMSConditionalLayout runat="server" id="layout1" Visible="<%= DocumentContext.CurrentDocument.GetValue("myValue").ToString() == "1"? true: false %>" >

Also tried:

<cms:CMSConditionalLayout runat="server" id="layout1"   >

<script runat="server">
  public override void DataBind() 
{ 

  string val = DocumentContext.CurrentDocument.GetValue("myValue").ToString();
    switch (val)
            {
                case "1":
                    laytou1.Visible = false;
                    break;
                case "2":
                    laytou2.Visible = false;
                    break;


                }

  }

</script>  

Any idea how I can get this to work?

Thanks :)

Recent Answers


Roman Hutnyk answered on August 19, 2015 19:15 (last edited on December 10, 2019 02:30)

Are you sure data bind event fires? Try page load.

Talking about following approach: have you tried Kentico macro instead of using server code? <cms:CMSConditionalLayout runat="server" id="layout1" Visible="<%= DocumentContext.CurrentDocument.GetValue("myValue").ToString() == "1"? true: false %>" >

like this:

Visible="{% CurrentDocument.MyField|(identity)GlobalAdministrator%}"

0 votesVote for this answer Mark as a Correct answer

Eagle Y answered on August 20, 2015 09:35

Thanks.

This is what I used:

<script runat="server">
  protected void Page_Load(object sender, EventArgs e)
    {
      bool showHide  = DocumentContext.CurrentDocument.GetValue("myValue").ToString() == "1"? true: false;
       layout1.Visible= showHide;
    }
</script>
0 votesVote for this answer Mark as a Correct answer

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