In the series Advanced Scripting Sample Apps we explain some use cases on how to use the Advanced Scripting. For more general info, it's very important that you read this KB-article first.
Use Case
In this example, we show different content on phone vs tablet vs the Browser Client
Instructions
Preparations
- Create a new app
- Add the following content items in the Root Collection:
- Placeholder for tablet
- Type: Placeholder
- Name:
tablet
- Title:
Tablet
- Placeholder for phone
- Type: Placeholder
- Name:
phone
- Title:
Phone
- Placeholder for browser
- Type: Placeholder
- Name:
browser
- Title:
Browser
- Placeholder for the other content
- Type: Placeholder
- Name:
any
- Title:
Any
- Placeholder for tablet
- Setup your Advanced Scripting (see below)
Advanced Scripting Settings
For the Root Collection:
// Executed once for every collection before the filtering of the items function setupFilter(collection, environment) { } // Executed for once for every collection function shouldShowCollection(collection, environment) { return true; } // Executed for every single content item function shouldShowItem(contentItem, collection, environment) { if (contentItem.Name == "browser") { return environment.IsBrowser(); } else if (contentItem.Name == "phone") { return environment.IsPhone(); } else if (contentItem.Name == "tablet") { return environment.IsTablet(); } else { return true; } } // Executed once for every collection after the filtering of the items function teardownFilter(collection, environment) { }