{"id":615,"date":"2012-10-15T23:44:56","date_gmt":"2012-10-16T05:44:56","guid":{"rendered":"https:\/\/toddbaginski.com\/blog\/?p=615"},"modified":"2013-06-28T15:43:33","modified_gmt":"2013-06-28T21:43:33","slug":"enabling-the-effectivedevicechannel-javascript-variable","status":"publish","type":"post","link":"https:\/\/toddbaginski.com\/blog\/enabling-the-effectivedevicechannel-javascript-variable\/","title":{"rendered":"Enabling The effectiveDeviceChannel JavaScript Variable"},"content":{"rendered":"<p>Device Channels in SharePoint can set a JavaScript variable that you can use to dynamically render content based on the Device Channels.\u00a0 The variable is called effectiveDeviceChannel.\u00a0 This variable is turned off by default.\u00a0 To enable it simply add a property named\u00a0 PublishingInformationControlIncludeEffectiveDeviceChannel to the property bag of the root site in your site collection and give it a value of true.<\/p>\n<p>Here\u2019s some PowerShell that does it.<\/p>\n<pre id=\"codeSnippet\">$web = Get-SPWeb <a href=\"http:\/\/wcm.powder.ski\/sites\/pso\">http:\/\/wcm.powder.ski\/sites\/pso<\/a><\/pre>\n<pre>$web.AllProperties[\"PublishingInformationControlIncludeEffectiveDeviceChannel\"] = \"true\"<\/pre>\n<pre>$web.Update()<\/pre>\n<p>After you add the property, you can access it inside a Display Template and react to the variable and render your content based on Device Channels, like this:<\/p>\n<p>&lt;!&#8211;#_<\/p>\n<p>}<\/p>\n<p>if(!line3.isEmpty &amp;&amp; effectiveDeviceChannel!=&#8221;Mobile&#8221;)<\/p>\n<p>{<\/p>\n<p>_#&#8211;&gt;<\/p>\n<p><span style=\"color: #800000; font-family: Consolas; font-size: x-small;\"><span style=\"color: #800000; font-family: Consolas; font-size: x-small;\"><span style=\"color: #800000; font-family: Consolas; font-size: x-small;\">&lt;div <\/span><\/span><\/span><span style=\"color: #ff0000; font-family: Consolas; font-size: x-small;\"><span style=\"color: #ff0000; font-family: Consolas; font-size: x-small;\"><span style=\"color: #ff0000; font-family: Consolas; font-size: x-small;\">class<\/span><\/span><\/span><span style=\"color: #0000ff; font-family: Consolas; font-size: x-small;\"><span style=\"color: #0000ff; font-family: Consolas; font-size: x-small;\"><span style=\"color: #0000ff; font-family: Consolas; font-size: x-small;\">=&#8221;cbs-pictureLine3 ms-textSmall ms-noWrap&#8221;<\/span><\/span><\/span><span style=\"color: #ff0000; font-family: Consolas; font-size: x-small;\"><span style=\"color: #ff0000; font-family: Consolas; font-size: x-small;\"><span style=\"color: #ff0000; font-family: Consolas; font-size: x-small;\">id<\/span><\/span><\/span><span style=\"color: #0000ff; font-family: Consolas; font-size: x-small;\"><span style=\"color: #0000ff; font-family: Consolas; font-size: x-small;\"><span style=\"color: #0000ff; font-family: Consolas; font-size: x-small;\">=&#8221;_#= line3Id =#_&#8221;<\/span><\/span><\/span><span style=\"color: #ff0000; font-family: Consolas; font-size: x-small;\"><span style=\"color: #ff0000; font-family: Consolas; font-size: x-small;\"><span style=\"color: #ff0000; font-family: Consolas; font-size: x-small;\">title<\/span><\/span><\/span><span style=\"color: #0000ff; font-family: Consolas; font-size: x-small;\"><span style=\"color: #0000ff; font-family: Consolas; font-size: x-small;\"><span style=\"color: #0000ff; font-family: Consolas; font-size: x-small;\">=&#8221;_#= line3 =#_&#8221;&gt;<\/span><\/span><\/span><span style=\"font-family: Consolas; font-size: x-small;\"><span style=\"font-family: Consolas; font-size: x-small;\">Model: _#= line3 =#_<\/span><\/span><span style=\"color: #0000ff; font-family: Consolas; font-size: x-small;\"><span style=\"color: #0000ff; font-family: Consolas; font-size: x-small;\"><span style=\"color: #0000ff; font-family: Consolas; font-size: x-small;\">&lt;\/<\/span><\/span><\/span><span style=\"color: #800000; font-family: Consolas; font-size: x-small;\"><span style=\"color: #800000; font-family: Consolas; font-size: x-small;\"><span style=\"color: #800000; font-family: Consolas; font-size: x-small;\">div<\/span><\/span><\/span><span style=\"color: #0000ff; font-family: Consolas; font-size: x-small;\"><span style=\"color: #0000ff; font-family: Consolas; font-size: x-small;\"><span style=\"color: #0000ff; font-family: Consolas; font-size: x-small;\">&gt;<\/span><\/span><\/span><\/p>\n<p><span style=\"color: #006400; font-family: Consolas; font-size: x-small;\"><span style=\"color: #006400; font-family: Consolas; font-size: x-small;\"><span style=\"color: #006400; font-family: Consolas; font-size: x-small;\">&lt;!&#8211;#_<\/span><\/span><\/span><\/p>\n<p>}<\/p>\n<p>This example only renders the Model number for an item displayed by the Content By Search Web Part that uses this Display Template.\u00a0 The Model number is mapped to the line3 variable.<\/p>\n<p>Here\u2019s what the output looks like in the Default Device Channel.\u00a0 Notice the Model number <strong>is displayed<\/strong> for the product.<\/p>\n<p><a href=\"https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2012\/10\/image3.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;\" title=\"image\" src=\"https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2012\/10\/image_thumb3.png\" alt=\"image\" width=\"284\" height=\"416\" border=\"0\" \/><\/a><\/p>\n<p>Here\u2019s what the output looks like in the Mobile Device Channel.\u00a0 Notice the Model number<strong> is not displayed<\/strong> for the product.<\/p>\n<p><a href=\"https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2012\/10\/image4.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;\" title=\"image\" src=\"https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2012\/10\/image_thumb4.png\" alt=\"image\" width=\"280\" height=\"433\" border=\"0\" \/><\/a><\/p>\n<p>Go get your ski goggles!\u00a0 ABasin opens in 2 days!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Device Channels in SharePoint can set a JavaScript variable that you can use to dynamically render content based on the Device Channels.\u00a0 The variable is called<span class=\"excerpt-hellip\"> [\u2026]<\/span><\/p>\n","protected":false},"author":1,"featured_media":618,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[96,99],"tags":[10,54,57,7,68],"class_list":["post-615","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-mobile","category-sharepoint-2013","tag-custom-development","tag-mobile","tag-mobility","tag-sharepoint","tag-sharepoint-2013"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/toddbaginski.com\/blog\/wp-json\/wp\/v2\/posts\/615","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/toddbaginski.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/toddbaginski.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/toddbaginski.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/toddbaginski.com\/blog\/wp-json\/wp\/v2\/comments?post=615"}],"version-history":[{"count":6,"href":"https:\/\/toddbaginski.com\/blog\/wp-json\/wp\/v2\/posts\/615\/revisions"}],"predecessor-version":[{"id":621,"href":"https:\/\/toddbaginski.com\/blog\/wp-json\/wp\/v2\/posts\/615\/revisions\/621"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/toddbaginski.com\/blog\/wp-json\/wp\/v2\/media\/618"}],"wp:attachment":[{"href":"https:\/\/toddbaginski.com\/blog\/wp-json\/wp\/v2\/media?parent=615"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/toddbaginski.com\/blog\/wp-json\/wp\/v2\/categories?post=615"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/toddbaginski.com\/blog\/wp-json\/wp\/v2\/tags?post=615"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}