Conditional Code in Master file - Front- & Back-End Development - Front- & Back-End Development - Progress Community
 Front- & Back-End Development

Conditional Code in Master file

  • Conditional Code in Master file
  • Hi,

    Is it possible to write conditional code in Sitefinity Master pages?.. so if no widgets are used for a placeholder, the markups for the empty placeholder does not show on the website. 

    For emaxple, I have this code for my sidebar in my Master file:

    <div class="Sidebar">
       <asp:contentplaceholder id="Sidebar" runat="server" />

    and this creates a div box in my wesbite (and I have some borders via CSS for this box).  Is it possible to include some conditional code to this so if a widget is dragged into this placeholder, it shows the div box on the website and if no widget is used, it doesn't show the div box.

  • Hello Marz,

    You can check if the div contains any html with a JQuery script on the master page. Something similar to this should do the job:

      if ($(".Sidebar").html().length > 0)
    Take a look at the following forum thread for further reference: 

    All the best,
    Jen Peleva
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items