Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I am using MOSS Publishing Pages. I want to dynamically create a header for sections if they are populated. This particular page layout has some fields that are required and they have static headers. I have a PublishingHTML section that is not required called Customer Feedback and one for additional links using SummaryLinks. If there is no Customer Feedback I want the heading hidden. I cannot use codeblock's in this site. I am hoping to use JQuery but so far have not had any luck.

Used Ashish's example for the summary links. I still have the issue with the PublishingRichHTML. Instead of hiding persay, I am adding the header instead or at least thats what I have working partially.

$.each(["CustomerFeedback"],  
    function (index, value) {  
        if ($("div[id*='_" + value +  
            "__ControlWrapper_RichHtmlField']").children()
            .length > 0)  
        {  
            $("div.CFHeader").html('Customer Feedback');  
        }  
    }); 

The problem is that if you just start typing in this the field and do not do any returns or formatting then no child tags are created. If you copy and paste or put in line breaks SharePoint automatically adds the tags at which point it works.

share|improve this question

2 Answers 2

up vote 1 down vote accepted

Ok figured this out, had a face meet hand moment. In the code I was using I was checking for child tags. There is the possibility that a user could just type in plain text and so no tags are generated. I just had to switch out children() with contents().

$(document).ready(function(){
$.each(["CustomerFeedback"],  
    function (index, value) {  
        if ($("div[id*='_" + value +  
            "__ControlWrapper_RichHtmlField']").contents()
            .length > 0)  
        {  
            $("div.CFHeader").html('Customer Feedback');  
        }  
    }); 
});
share|improve this answer

Since you have not provided the content of your page, I'll try to provide the solution with example. Let's assume you have additional summary link markup like:

 <div id="leftAdditionalLinks">
    <h2>
        Additional Links</h2>   
        <PublishingWebControls:SummaryLinkFieldControl FieldName="AdditionalLinks" runat="server">
                        </PublishingWebControls:SummaryLinkFieldControl>
     </div>

Now you need to hide entire div (during display mode) when there are no links authored. The jQUERY would look something like:

// Make sure page is in design mode
if ($('#MSOLayout_InDesignMode').val() == "") {
    // if div tag has no a tag (no summary link item), hide it
    $("Div#leftAdditionalLinks").not(":has('a')").hide();

}

In general, you may need to wrap the header and field control inside a container like div and then look for a condition which is true when no content is authored and hide it - as shown above.

share|improve this answer
    
Excellent, thanks. At least this solves the summarylinks portion. Still have an issue with the PublishingRichHTML. I am editing the post –  Perplexed Mar 5 '12 at 18:43

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.