Skip Ribbon Commands
Skip to main content

Dynamic Page Layouts in SharePoint 2013 - Part 4

Rendering the Dynamic Page

James Strugnell

02/11/2016

​This is the 4th (and likely final) part of our series on how we built a dynamic page template in SharePoint 2013, enabl​ing content managers to configure a custom grid layout within the page. You can find the previous articles in the series here:

In this article we're going to cover the code which consumes the current page level configuration and renders out the user-configured rows, including the web part zones, which comprise the page.​

​​Custom Page Layout and Web Control

Firstly, we created a custom Page Layout called "Dynamic Page Template". We then added to that page a custom ASP.Net web control, DynamicWebPartZoneRenderer.cs. The entire page template can be viewed ​here:

https://github.com/jstrugnell/SharePointDynamicPageLayouts/blob/master/DynamicPageLayouts/Common/Branding/PageLayouts/dynamic.aspx

The custom web control can be viewed here:

https://github.com/jstrugnell/SharePointDynamicPageLayouts/blob/master/DynamicPageLayouts/Common/WebControls/DynamicWebPartZoneRenderer.cs

Loading the Current Page Configuration

As established in the previous articles, the page configuration data is stored as a JSON string in a SharePoint field for the current page. For a quick recap, the first action performed by the DynamicWebPartZoneRenderer control is to pull the configuration JSON data out of the page field, and de-serialize into a C# object, of type "PageWebPartZoneConfiguration". This class is essentially a collection of "Row Configurations" each of which represents s single row as configured by the page editor. Each Row has the following available settings (we actually implemented more in the real solution):

  • Id – This is a unique ID (GUID)
  • Order – This number enforces the sequence in which the rows are added to the page
  • BackgroundColour – This is used as the background colour of the entire row
  • MarginTop – This is the gap that should be injected above the current row
  • MarginBottom – This is the gap that should be injected below the current row
  • PaddingTop – This is the gap that should be injected between the content and the top of the row
  • PaddingBottom – This is the gap that should be injected between the content and the bottom of the row
  • Layout – Perhaps the most important setting, this field represents the layout for the row. We have defined a number of pre-defined layouts that content editors can choose from. Each layout is implemented as a "User Control", made up of one or more Web Part Zones, and is loaded dynamically on to the page.

So once we have the configuration data de-serialized, we can then loop over each row and dynamically render the User Control associated with the "Layout" property. Some of the configuration for each Layout is hard coded in the HTML, for example the number of columns that exist. Other aspects, such as the margin, padding and background colour, need to be set at run-time. This is done in the Base Control from which each Layout User Control inherits - BaseWebPartZoneLayout.

BaseWebPartZoneLayout

Each Row Layout User Control inherits from a single base user control called "BaseWebPartZoneLayout". Each User Control is implemented consistently with known conventions. This allows the Base Control to manipulate the layout elements according to the configuration set for the current Row. For example, every Row User Control has an ASP.Net Panel with an ID of pnlRow. We then reference that Panel from the Base Control and configure its background colour, margin and padding according to the applied configuration.

We also implement the "Edit" button from this Base Control. We detect if the page is currently in Edit mode and then render out a link for each Row which enables the logged-in user to open up and manage the settings for each row.

Configuring the Web Part Zones

If you recall from the first article in this series (all those months ago...), the first hurdle we had to overcome was whether we could dynamically add Web Part Zones to a page. We now know that this is indeed possible but we never fully explained quite how. The big issue was that every Web Part Zone needs to have a unique ID. It also needs to maintain that ID through page postbacks and reloads. Each Web Part Zone also needed to maintain the same ID even if its parent Row was repositioned within the page. So how did we ensure all of this?

Each Web Part Zone is statically added in to its parent User Control. They are purposely not assigned an ID at this stage as they need to be unique to the whole page. So how do we assign these IDs uniquely and consistently?

After the Layout Control has been loaded and initialised (e.g. Colour, Padding, Margins assigned) we then pass an instance of the User Control (via a handle on the Base Control) into a method called "ConfigureChildWebPartZones". This method also receives the "ID" (GUID) for the current Row.

We then loop over each "Control" inside the User Control recursively hunting for any Web Part Zones. When we find one, we then set its ID to a concatenated string comprising of the literal string "dynamicZone_" plus the row ID, plus the index of the Web Part Zone (i.e. if it's the first Web Part Zone we hit, this will be number 1).

Once this process has finished every Web Part Zone is assigned a unique ID, and one that persists even when the Row is moved around the page. If the Content Author changes the designated Layout configuration then any Web Parts within will potentially move. This is not a big problem however, and can be resolved by the editing user.

Please review the code on Github for a complete picture of the process outlined above.

Conclusion

That brings us to the end of this series. Hopefully it has served to present a number of useful techniques that have been brought together to build a much-used feature on our custom web platform. The customisable row settings detailed in this series are really just a starting point. Any number of other possible settings could be applied further enhancing the options and opportunities to page editors.

We have placed a cut down working version of this solution on Github which can be found here: https://github.com/jstrugnell/SharePointDynamicPageLayouts

If you have any questions or suggestions for other enhancements or improvements please get in touch.

Thanks.​





 About us

Fuse Collaboration Services is a Cloud Solution Provider and Microsoft Gold Partner specialising in delivering SharePoint, Skype for Business, and Azure cloud-based solutions. Based in Northampton, UK.

Microsoft Gold Partner Logo showing 5 competencies

Read more

 Latest Tweets

 Latest Blog

 

 

Clear out the ROT!140<p class="lead">​​They might give examples of damp rot or rotten food but ROT in the IT world is an acronym and if you apply the definition of rot to your data it's not far off what this blog is essentially about.</p><p class="lead">The acronym ROT when referring to IT stands for <strong>Redundant, Obsolete and Trivial</strong> and it's used when describing your digital data that your business keeps hold of when it has no value. Employees create ROT every day without realising how much this impacts your business.</p><p>ROT can be found on network and SharePoint servers, desktops, mobile devices such as laptops and mobile phones, on premise and in the cloud. Its impact can be huge and will become even more of a worry when the new GDPR* comes into force on May 25<sup>th</sup> 2018. </p><p>​ <strong>Reasons to clear the ROT out&#58;</strong></p><ol>​ <li> <strong>It decreases the need for extra storage.</strong><br>Funding extra storage, costs businesses money; not only having to pay for the extra storage but extra storage creates the need for a bigger IT infrastructure (and more IT support staff) and hardware which all rise costs.<br></li><li> <strong>Prevents data becoming a liability risk.</strong>​ <br>For businesses that are subject to audits, clearing out the ROT is an important part of the process. Businesses need to be able to demonstrate they are compliant within a whole range of regulations and legal guidelines dependent on the sector the business operates in.<br></li><li> <strong>Improves productivity in staff</strong>. <br>The need to quickly access the right information instead of wading through irrelevant documents will increase the delivery of projects and increase productivity on a day to day basis. This in turn increases productivity and profit margins.<br></li><li> <strong>Prevents data breaches.</strong><br>Clearing out the ROT can be viewed as time consuming and not a profitable use of time. The less information your company has that has no business or legal value reduces the chance of a data breach. If there is a data breach then you open yourselves up to costly legal action that is easily preventable.<br></li><li> <strong>GDPR is coming.</strong><br>May 25<sup>th</sup> 2018 is a date that you need to have etched in your brain if you are the owner of a business. The new regulations are replacing the outdated Data Protection Act and is a well needed reaction to the change in how data is stored, transferred and managed. Individual's now have far more rights and businesses will have to ensure that they have the legal consent to process data. All personal data that you hold, where it came from and who you share it with now needs to be documented. Getting rid of obsolete data will help to prevent any breaches of GDPR.<br></li> ​ </ol> <p class="small">*GDPR(The General Data Protection Regulation) is the European Union's new legislation to protect the personal data of all EU citizens and has evolved from the need to regulate data protection by updating the 1995 Data Protection Directive (DPD). This set of regulations is now out of date due to the increasing advances in the digital and technology world.<br>Organisations have been given a two-year lead in period to become compli​ant, ending 25th May 2018.​</p><p> <strong>How can Fuse help you clear out the ROT?</strong></p><p>Fuse is a specialist in SharePoint and has an in-house team of consultants. If you currently store terabytes of data held within an on-premise infrastructure and you are worried about GDPR because your data is unstructured and therefore unmanageable, Fuse can help. Fuse implements solutions that help to analyse the data held by your organisation; structure your data; identify unwanted and duplicated data. This is all done quickly and securely. </p><p>Once your data is in a manageable format we can provide the tools that will identify and collect GDPR personal information within documents. Workflows can be created to generate documents and automate your requests for &quot;the right to be forgotten&quot;. &#160;Not only are we good at it, it will give you peace of mind as you will be preventing any GDPR breaches. Become compliant by binning the ROT! </p><div class="well well-lg"><p class="lead">​If you have any questions or would like to speak to someone about your current system, call 01604 797979 for​ a no obligation chat!</p></div>l.ozier@fusecollaboration.com | Louise Ozier | 693A30232E777C6675736563735C6C2E6F7A696572 i:0#.w|fusecs\l.ozier24/07/2017 23:00:002017-07-24T23:00:00ZIf you were to ask most people what the definition of rot is, you are more than likely to get answers along the lines of "something that's damaged, something that you can't use anymore or something that is decaying or gone bad". 26/07/2017 10:55:54htmlFalseaspx

 Contact us

Our address
12-14 Brookfield, Duncan Close
Moulton Park, Northampton
NN3 6WL
P: +44(0)1604 797979
Contact Us