none
Adding Div when provision webpart declaratively in page RRS feed

  • Question

  • Hi,

    I m provisionning declaratively  a Webpart inside a page so the structure of my Schema.xml is like this

        <WebParts>
              
              <AllUsersWebPart WebPartZoneID="Main" WebPartOrder="0">
                <![CDATA[
                                 <?xml version="1.0" encoding="utf-8"?>
                                 <div id="Test1">
                                 <WebPart xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/WebPart/v2">
                                  <Title>sample Info</Title>
                                  <FrameType>None</FrameType>
                                  <Description>Allows authors to enter rich text content.</Description>
                                  <IsIncluded>true</IsIncluded>

    I want to insert a div <div id="Test1">

    to englobe the webpart generated but seems that when the page is created the div is not generated does anyone knows how to perform this.

    Thanks for your help
    • Edited by Kitano Thursday, January 5, 2017 11:41 AM
    Thursday, January 5, 2017 11:39 AM

All replies

  • you can't set parent DOM element of web part by modifying webpart file. But it is possible to add it via jQuery - see wrap function. You need to find DOM element which corresponds to provisioned web part - it is also can be done by jQuery selectors, e.g. by searching elements by web part title.

    Blog - http://sadomovalex.blogspot.com
    Dynamic CAML queries via C# - http://camlex.codeplex.com

    Thursday, January 5, 2017 1:40 PM
  • Hi,

    As sadomovalex's reply, we can add your web part in to the DIV element using jQuery, please add the following code into a Script Editor web part or Content Editor web part in the web part page.

    <script src="//code.jquery.com/jquery-3.1.0.min.js" type="text/javascript"></script>
    <script type="text/javascript">
    $(function () {
        $(".ms-webpart-chrome-title span[title='sample Info']").closest("div[id^='MSOZoneCell_WebPartWPQ']").wrap("<div id='Test1'></div>");
    });
    </script>

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Friday, January 6, 2017 5:08 AM
    Moderator
  • Hi,

    Any update?

    If the replies help you, please mark the reply as answer, it will make others who stuck with the similar issue easier to search for valid solutions in this forum.

    Thanks


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Tuesday, January 10, 2017 9:32 AM
    Moderator