Skip Ribbon Commands
Skip to main content

Dynamic Page Layouts in SharePoint 2013 - Part 2

Persisting Page Configuration

James Strugnell

05/09/2016

​This is another article in our series explaining how we built a Dynamic Page Layout system in SharePoint 2013. For an introduction please read here​. In this post I'm going to cover how we persist the page level configuration for our Dynamic Page Template. i.e. how each row in our Dynamic Page is configured, and ordered. 

To recap, each row is configurable to use a specific template (i.e. Full Width, 2 columns, 3 columns etc.). In addition to the template used, we also need to store where on the page the row should go (a positional index), if it should have a background colour, top/bottom margin and top/bottom padding and any other required Row-level configuration options. So we needed a place and method to store this configuration as part of every dynamic page. 

Our plan was to use a JSON object for the data and then store it somewhere within each page, as part of that page. We could then enable an editor interface, within the page, that would allow content editors to add, edit and delete rows as needed. Thus when they save the page, they will save the configuration data along with it. We would then be able to read this configuration out on page load, loop over it, and render the required Templates (which are essentially User Controls) and then run some code over each row template to initialise the child Web Part Zones with unique IDs (a problem covered in a later post).

That was the concept, how could we do it.

Where and How to Store the JSON Configuration

Firstly, how could we store the JSON object within the page. My first thought was that we could leverage the Property Bag for the page. If you aren't aware of the Property Bag it is a SharePoint concept where almost every type of object (container) in SharePoint (Farm, Web App, Site collection, Site, List, Item etc.) has an associated "Property Bag" which is a Key/Value pair storage area. It is normally ideal for configuration data, however I had a better idea for this scenario.

Given that we are working with Publishing Pages, we have access to "Fields" within each page. For the project we were working on we had access to a "Base Page" Content Type from which every Publishing Page type inherited. So I added a new field called DynamicPageConfiguration to the Base Page Content Type. This was a multiline text field of type "Note", configured to use 20 rows. As the field was always likely to exceed 255 characters we also had to set the property "UnlimitedLengthInDocumentLibrary" to "TRUE".

So we now had a field available to us on every page in which we could store text (JSON) data. I added this field to the Dynamic Page Template and it showed up on the page as an editable textbox field. You can see in the following code how we wrapp it in an EditModePanel so that it only rendered in the page while in "Edit" mode (funny that). We also set it to be hidden using CSS so that it wasn't actually visible on the page. We didn't want Content Managers to edit the field directly, we would build an interface that then read and wrote to this field in the background.

The beauty of this approach was that SharePoint would save the data in this field for us, without us having to anything. It was just a field on the page. You might notice that the field has an additional CSS Class of "js-DynamicPageConfiguration". This is the selector used from JavaScript when a user edits the page configuration through a popup form. I will go into more detail on that process in my next post.

To help understand the configuration data being stored on each page, here is an example of the JSON stored in this field, as viewed using the ever useful online JSON Viewer tool:

Dynamic Page Config JSON.png

Hopefully the concepts are coming together for you now, and perhaps even making sense (?). Later in this series you will see how we added a control on the Dynamic Page template that iterates over the JSON configuration data above and loads the associated User Controls to render the required columns. Content Managers then interact with this page in edit mode, adding and editing rows of Web Part Zones, and then adding Web Parts into those zones. Here's a sneak preview of how that looks. In the screen grab below I've just clicked to edit an existing Row (using the Cog icon in the top-right of each row). You can also see the option to "Add new dynamic row" along the bottom, which initiates the same form.

Dynamic Page Row Form.png

We'll cover how the above form works in the next post. Until then, thanks for reading.



 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

 

 

Get single sign-on for all apps3995<p class="lead">​​​Are you looking for an identity-as-a-service (IDaaS) solution that solves your biggest IT challenges without compromising user experience?</p><p class="lead">With Azure Active Directory, the Microsoft IDaaS solution, you can streamline the employee experience with single sign-on capabilities and reduce the complexity of managing identity, security, and access to your company’s critical data. You get a proven solution that allows you to&#58;​</p><hr />​ <div class="lead"><div class="row"><div class="col-md-6">​ <div class="media"> <img class="img-responsive pull-left" src="/ourblog/Blog%20Site%20Images/image004.png" alt="" />​ ​ <div class="media-body">​​Quickly adopt cloud services​</div></div></div>​ <div class="col-md-6">​ <div class="media"> <img class="img-responsive pull-left" src="/ourblog/Blog%20Site%20Images/image006.png" alt="" /> <div class="media-body">Improve application security</div></div></div>​ ​</div>​ <div class="row"><div class="col-md-6">​ <div class="media"> <img class="img-responsive pull-left" src="/ourblog/Blog%20Site%20Images/image008.png" alt="" /> <div class="media-body">Empower employees with access to world-class cloud apps</div></div></div><div class="col-md-6">​ <div class="media"> <img class="img-responsive pull-left" src="/ourblog/Blog%20Site%20Images/image010.png" alt="" /> <div class="media-body">Monitor application usage and protect your business</div></div></div></div>​ <div class="row"><div class="col-md-6">​ <div class="media"> <img class="img-responsive pull-left" src="/ourblog/Blog%20Site%20Images/image012.png" alt="" /> <div class="media-body">Easily and securely manage employee and vendor access</div></div></div><div class="col-md-6">​ <div class="media"> <img class="img-responsive pull-left" src="/ourblog/Blog%20Site%20Images/image014.png" alt="" /> <div class="media-body">Secure remote, mobile access to on-premises apps</div></div></div>​ </div><div class="row"><div class="col-md-6">​ <div class="media"> <img class="img-responsive pull-left" src="/ourblog/Blog%20Site%20Images/image016.png" alt="" /> <div class="media-body">Implement consistent, self-service application access management</div></div></div>​​​ </div></div><hr /><p class="lead"><a href="/_layouts/15/FIXUPREDIRECT.ASPX?WebId=4fc45909-2b6d-48b9-bcf9-a446e9d472d6&amp;TermSetId=c98895cd-d37f-4406-9cff-5480b4f829b6&amp;TermId=218eb0be-10f6-490a-82a7-a7fd47c8de90">Contact Fuse</a> to discuss how we can help implement IDaaS within your organisation, using our expertise and experience to reduce risk and project length.​</p> <div class="well well-lg"><p class="lead">Are you curious about how Azure Active Directory can work for you? <a href="/_layouts/15/FIXUPREDIRECT.ASPX?WebId=4fc45909-2b6d-48b9-bcf9-a446e9d472d6&amp;TermSetId=c98895cd-d37f-4406-9cff-5480b4f829b6&amp;TermId=721159e3-34c0-40dc-8028-ae2e2f2e79e4">Let us show you how​</a>!​</p></div>​​a.walman@fusecollaboration.com | Andrew Walman | 693A30232E777C6675736563735C612E77616C6D616E i:0#.w|fusecs\a.walman17/01/2018 00:00:002018-01-17T00:00:00Zno matter where they liveAzure Active Directory, the Microsoft IDaaS solution23/02/2018 23:55:232757htmlFalseaspx

 Contact us

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