Try Now
More in this section

Forums / Designing & Styling / Conditional Code in Master file

Conditional Code in Master file

2 posts, 0 answered
  1. Marz
    Marz avatar
    7 posts
    29 Aug 2012
    25 Sep 2012
    Link to this post

    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.

  2. Jen Peleva
    Jen Peleva avatar
    568 posts
    10 Sep 2016
    28 Sep 2012
    Link to this post
    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
2 posts, 0 answered