Conditional Code in Master file

Posted by Community Admin on 05-Aug-2018 15:57

Conditional Code in Master file

All Replies

Posted by Community Admin on 25-Sep-2012 00:00

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" />
</div>

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.

Thanks,
Marz

Posted by Community Admin on 28-Sep-2012 00:00

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:

$(document).ready(function()
  if ($(".Sidebar").html().length > 0)
    $(".Sidebar").show();
                                            
);
Take a look at the following forum thread for further reference:
http://stackoverflow.com/questions/3893440/if-div-has-content-show-div 

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

This thread is closed