Enabling the effective DeviceChannel JavaScript Variable in SharePoint

Here's the PowerShell to do it

Todd Baginski

by Todd Baginski on 4/16/2014

Share this:

Article Details

Date Revised:

Sponsored by

Device Channels in SharePoint can set a JavaScript variable that you can use to dynamically render content based on the Device Channels.  The variable is called effectiveDeviceChannel.  This variable is turned off by default.  To enable it simply add a property named  PublishingInformationControlIncludeEffectiveDeviceChannel to the property bag of the root site in your site collection and give it a value of true.

Here’s some PowerShell that does it.

$web = Get-SPWeb http://wcm.powder.ski/sites/pso
$web.AllProperties["PublishingInformationControlIncludeEffectiveDeviceChannel"] = "true"

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:



if(!line3.isEmpty && effectiveDeviceChannel!=”Mobile”)



<div class=”cbs-pictureLine3 ms-textSmall ms-noWrap”id=”_#= line3Id =#_”title=”_#= line3 =#_”>Model: _#= line3 =#_</div>



This example only renders the Model number for an item displayed by the Content By Search Web Part that uses this Display Template.  The Model number is mapped to the line3 variable.

Here’s what the output looks like in the Default Device Channel.  Notice the Model number is displayed for the product.


Here’s what the output looks like in the Mobile Device Channel.  Notice the Model number is not displayed for the product.


Go get your ski goggles!  ABasin opens in 2 days!

- See more at: http://toddbaginski.com/blog/enabling-the-effectivedevicechannel-javascript-variable/#sthash.gZAuR7gU.dpuf

Topic: Social and Mobile Workplace

Sign in with

Or register