{"id":869,"date":"2015-01-30T12:22:08","date_gmt":"2015-01-30T12:22:08","guid":{"rendered":"http:\/\/www.myfatblog.co.uk\/?p=869"},"modified":"2015-04-24T14:36:47","modified_gmt":"2015-04-24T14:36:47","slug":"mds-enabled-sub-sites-and-display-templates","status":"publish","type":"post","link":"http:\/\/www.myfatblog.co.uk\/index.php\/2015\/01\/mds-enabled-sub-sites-and-display-templates\/","title":{"rendered":"MDS Enabled Sub-sites and Display Templates"},"content":{"rendered":"<p>Last year I released some of my templates for JSlink onto the SPCSR repository, but I was never totally happy with the solution for MDS (Minimal Download Strategy) enabled sites.<\/p>\n<p>Basically, in order to make sure that MDS recognises our scripts and doesn\u2019t remove them when it\u2019s processing the page refresh, we had to use the RegisterModuleInit method, with the path to our script and then the method to call once loaded.<\/p>\n<p>This looked like:-<\/p>\n<div id=\"scid:C89E2BDB-ADD3-4f7a-9810-1B7EACF446C1:3136d349-eaf0-4156-b870-90b91c59494e\" class=\"wlWriterEditableSmartContent\" style=\"margin: 0px; padding: 0px; float: none; display: inline;\">\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nRegisterModuleInit(&quot;\/_catalogs\/masterpage\/Display%20Templates\/csr_ovr_RenderFormManager.js&quot;, pfh.RegisterTemplateOverride);\r\n\r\n\/\/or for a sub-site\r\n\r\nRegisterModuleInit(&quot;\/Sites\/HR\/_catalogs\/masterpage\/Display%20Templates\/csr_ovr_RenderFormManager.js&quot;, pfh.RegisterTemplateOverride);\r\n<\/pre>\n<\/div>\n<p>This meant that to use the display templates in multiple site collections that had MDS enable, you had to create multiple copies of the template, address for each site collection.<\/p>\n<p>Obviously that isn\u2019t ideal, so when I was looking at this problem for my session at the Evolutions Conference in April, I realised that MDS enabled sites have a very predictable URL of :-<\/p>\n<p>HTTPS:\/\/HOSTNAME\/<strong><em>_LAYOUTS\/15\/START.aspx\/<\/em><\/strong><\/p>\n<div id=\"scid:C89E2BDB-ADD3-4f7a-9810-1B7EACF446C1:f5d0000f-a002-4c19-80f5-ea9d4be53f97\" class=\"wlWriterEditableSmartContent\" style=\"margin: 0px; padding: 0px; float: none; display: inline;\">\n<pre class=\"brush: jscript; collapse: false; pad-line-numbers: true; title: ; notranslate\" title=\"\">\r\npfh.sitecolpath = window.location.pathname.substring(0,window.location.pathname.indexOf(&quot;\/_layouts\/15\/start.aspx&quot;))\r\nRegisterModuleInit(pfh.sitecolpath + &quot;\/_catalogs\/masterpage\/Display%20Templates\/csr_ovr_RenderFormManager.js&quot;, pfh.RegisterTemplateOverride);\r\n<\/pre>\n<p>In the event that we have a non MDS enable site, the RegisterModuleInit is ignored, so it doesn\u2019t matter that the path is wrong.<\/p>\n<p>I\u2019ve tested this in IE and Chrome which both respond well, so I\u2019ve updated the display templates in GitHub. (<a href=\"https:\/\/github.com\/SPCSR\"><span style=\"text-decoration: underline;\"><span style=\"color: #0066cc;\">https:\/\/github.com\/SPCSR<\/span><\/span><\/a>)<\/p>\n<p>Paul.<\/p>\n<blockquote><p><del datetime=\"2015-02-04T21:00:39+00:00\">After I posted this, Elio Struyf sent me a quick tweet reminding me of the _spPageContextInfo object, and more specifically the .siteAbsoluteUrl property, which gives the absolute URL for the current site collection.<\/del><\/p>\n<p><del>This is a much better way of doing it, so I shall adopt this method instead.<\/del><\/p>\n<p><del>The code now reads:-<\/del><\/p>\n<pre class=\"brush: jscript; collapse: false; pad-line-numbers: true; title: ; notranslate\" title=\"\">\r\nRegisterModuleInit(_spPageContextInfo.siteAbsoluteUrl + &quot;\/_catalogs\/masterpage\/Display%20Templates\/csr_ovr_RenderFormManager.js&quot;, pfh.RegisterTemplateOverride);\r\n<\/pre>\n<p>&nbsp;<\/p><\/blockquote>\n<\/div>\n<blockquote><p>Well unfortunately, the spPageContextInfo seems to have an issue.. it doesn&#8217;t always get populated before the Display Template registration is performed, so every now and again the object is null and your display template refuses to load. so I&#8217;m going to drop back to my first method of calculating the URL on the fly!<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>Last year I released some of my templates for JSlink onto the SPCSR repository, but I was never totally happy with the solution for MDS (Minimal Download Strategy) enabled sites. Basically, in order to make sure that MDS recognises our scripts and doesn\u2019t remove them when it\u2019s processing the page refresh, we had to use &hellip; <\/p>\n<p><a class=\"more-link btn\" href=\"http:\/\/www.myfatblog.co.uk\/index.php\/2015\/01\/mds-enabled-sub-sites-and-display-templates\/\">Continue reading<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"categories":[96,29,51],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>MDS Enabled Sub-sites and Display Templates - Blog of an overweight SharePoint addict<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"http:\/\/www.myfatblog.co.uk\/index.php\/2015\/01\/mds-enabled-sub-sites-and-display-templates\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"MDS Enabled Sub-sites and Display Templates - Blog of an overweight SharePoint addict\" \/>\n<meta property=\"og:description\" content=\"Last year I released some of my templates for JSlink onto the SPCSR repository, but I was never totally happy with the solution for MDS (Minimal Download Strategy) enabled sites. Basically, in order to make sure that MDS recognises our scripts and doesn\u2019t remove them when it\u2019s processing the page refresh, we had to use &hellip; Continue reading\" \/>\n<meta property=\"og:url\" content=\"http:\/\/www.myfatblog.co.uk\/index.php\/2015\/01\/mds-enabled-sub-sites-and-display-templates\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog of an overweight SharePoint addict\" \/>\n<meta property=\"article:published_time\" content=\"2015-01-30T12:22:08+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2015-04-24T14:36:47+00:00\" \/>\n<meta name=\"author\" content=\"Cimares\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@cimares\" \/>\n<meta name=\"twitter:site\" content=\"@cimares\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Cimares\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"http:\/\/www.myfatblog.co.uk\/index.php\/2015\/01\/mds-enabled-sub-sites-and-display-templates\/\",\"url\":\"http:\/\/www.myfatblog.co.uk\/index.php\/2015\/01\/mds-enabled-sub-sites-and-display-templates\/\",\"name\":\"MDS Enabled Sub-sites and Display Templates - Blog of an overweight SharePoint addict\",\"isPartOf\":{\"@id\":\"http:\/\/www.myfatblog.co.uk\/#website\"},\"datePublished\":\"2015-01-30T12:22:08+00:00\",\"dateModified\":\"2015-04-24T14:36:47+00:00\",\"author\":{\"@id\":\"http:\/\/www.myfatblog.co.uk\/#\/schema\/person\/55ae8f6885bb5b8390dad001f3da83c6\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/www.myfatblog.co.uk\/index.php\/2015\/01\/mds-enabled-sub-sites-and-display-templates\/\"]}]},{\"@type\":\"WebSite\",\"@id\":\"http:\/\/www.myfatblog.co.uk\/#website\",\"url\":\"http:\/\/www.myfatblog.co.uk\/\",\"name\":\"Blog of an overweight SharePoint addict\",\"description\":\"The rantings of a (not so) food obsessed IT consultant!\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/www.myfatblog.co.uk\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"http:\/\/www.myfatblog.co.uk\/#\/schema\/person\/55ae8f6885bb5b8390dad001f3da83c6\",\"name\":\"Cimares\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/www.myfatblog.co.uk\/#\/schema\/person\/image\/\",\"url\":\"http:\/\/www.myfatblog.co.uk\/images\/BlogImages\/About_D057\/TopOfTheWorld.jpg\",\"contentUrl\":\"http:\/\/www.myfatblog.co.uk\/images\/BlogImages\/About_D057\/TopOfTheWorld.jpg\",\"caption\":\"Cimares\"},\"sameAs\":[\"http:\/\/www.myfatblog.co.uk\"],\"url\":\"http:\/\/www.myfatblog.co.uk\/index.php\/author\/reginald\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"MDS Enabled Sub-sites and Display Templates - Blog of an overweight SharePoint addict","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"http:\/\/www.myfatblog.co.uk\/index.php\/2015\/01\/mds-enabled-sub-sites-and-display-templates\/","og_locale":"en_US","og_type":"article","og_title":"MDS Enabled Sub-sites and Display Templates - Blog of an overweight SharePoint addict","og_description":"Last year I released some of my templates for JSlink onto the SPCSR repository, but I was never totally happy with the solution for MDS (Minimal Download Strategy) enabled sites. Basically, in order to make sure that MDS recognises our scripts and doesn\u2019t remove them when it\u2019s processing the page refresh, we had to use &hellip; Continue reading","og_url":"http:\/\/www.myfatblog.co.uk\/index.php\/2015\/01\/mds-enabled-sub-sites-and-display-templates\/","og_site_name":"Blog of an overweight SharePoint addict","article_published_time":"2015-01-30T12:22:08+00:00","article_modified_time":"2015-04-24T14:36:47+00:00","author":"Cimares","twitter_card":"summary_large_image","twitter_creator":"@cimares","twitter_site":"@cimares","twitter_misc":{"Written by":"Cimares","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"http:\/\/www.myfatblog.co.uk\/index.php\/2015\/01\/mds-enabled-sub-sites-and-display-templates\/","url":"http:\/\/www.myfatblog.co.uk\/index.php\/2015\/01\/mds-enabled-sub-sites-and-display-templates\/","name":"MDS Enabled Sub-sites and Display Templates - Blog of an overweight SharePoint addict","isPartOf":{"@id":"http:\/\/www.myfatblog.co.uk\/#website"},"datePublished":"2015-01-30T12:22:08+00:00","dateModified":"2015-04-24T14:36:47+00:00","author":{"@id":"http:\/\/www.myfatblog.co.uk\/#\/schema\/person\/55ae8f6885bb5b8390dad001f3da83c6"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/www.myfatblog.co.uk\/index.php\/2015\/01\/mds-enabled-sub-sites-and-display-templates\/"]}]},{"@type":"WebSite","@id":"http:\/\/www.myfatblog.co.uk\/#website","url":"http:\/\/www.myfatblog.co.uk\/","name":"Blog of an overweight SharePoint addict","description":"The rantings of a (not so) food obsessed IT consultant!","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/www.myfatblog.co.uk\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"http:\/\/www.myfatblog.co.uk\/#\/schema\/person\/55ae8f6885bb5b8390dad001f3da83c6","name":"Cimares","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/www.myfatblog.co.uk\/#\/schema\/person\/image\/","url":"http:\/\/www.myfatblog.co.uk\/images\/BlogImages\/About_D057\/TopOfTheWorld.jpg","contentUrl":"http:\/\/www.myfatblog.co.uk\/images\/BlogImages\/About_D057\/TopOfTheWorld.jpg","caption":"Cimares"},"sameAs":["http:\/\/www.myfatblog.co.uk"],"url":"http:\/\/www.myfatblog.co.uk\/index.php\/author\/reginald\/"}]}},"_links":{"self":[{"href":"http:\/\/www.myfatblog.co.uk\/index.php\/wp-json\/wp\/v2\/posts\/869"}],"collection":[{"href":"http:\/\/www.myfatblog.co.uk\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.myfatblog.co.uk\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.myfatblog.co.uk\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.myfatblog.co.uk\/index.php\/wp-json\/wp\/v2\/comments?post=869"}],"version-history":[{"count":10,"href":"http:\/\/www.myfatblog.co.uk\/index.php\/wp-json\/wp\/v2\/posts\/869\/revisions"}],"predecessor-version":[{"id":893,"href":"http:\/\/www.myfatblog.co.uk\/index.php\/wp-json\/wp\/v2\/posts\/869\/revisions\/893"}],"wp:attachment":[{"href":"http:\/\/www.myfatblog.co.uk\/index.php\/wp-json\/wp\/v2\/media?parent=869"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.myfatblog.co.uk\/index.php\/wp-json\/wp\/v2\/categories?post=869"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.myfatblog.co.uk\/index.php\/wp-json\/wp\/v2\/tags?post=869"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}