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 how to use the twxlog
functions and also highlight the lifecycle of the Advanced Scripting. This is ideal to debug while setting up your Advanced Scripting scenario!
Instructions
Preparations
- Create a new app
- Enable the Hamburger Menu
- Add a content item in the Root Collection with the following properties:
- Type: Placeholder
- Name:
item-root
- Title:
Root Collection Item
- Add a content item in the Hamburger Menu Collection with the following properties:
- Type: Placeholder
- Name:
item-hamburger
- Title:
Hamburger Item
- Add a new Collection with the name Sample Collection
- Add a Content Item in the Sample Collection with the following properties:
- Type: Placeholder
- Name:
item-sample
- Title:
Sample Collection Item
- Set up your Advanced Scripting (see below)
- Run the app in the Twixl app and then go to the Gear menu > Advanced Filter Log to see the log messages.
- For the Browser Client, open the Root Collection, append
?debug=1
to the url and you'll see the debug icon in the toolbar.
Advanced Scripting Settings
For the Root Collection:
// Executed once for every collection before the filtering of the items function setupFilter(collection, environment) { twxlog.Info("setupFilter: " + collection.Name); } // Executed for once for every collection function shouldShowCollection(collection, environment) { twxlog.Info("shouldShowCollection: " + collection.Name); return true; } // Executed for every single content item function shouldShowItem(contentItem, collection, environment) { twxlog.Info("shouldShowItem: " + collection.Name + ", " + contentItem.Name); return true; } // Executed once for every collection after the filtering of the items function teardownFilter(collection, environment) { twxlog.Info("teardownFilter: " + collection.Name); }
For the Hamburger Menu Collection:
// Executed once for every collection before the filtering of the items function setupFilter(collection, environment) { twxlog.Info("setupFilter: " + collection.Name); } // Executed for once for every collection function shouldShowCollection(collection, environment) { twxlog.Info("shouldShowCollection: " + collection.Name); return true; } // Executed for every single content item function shouldShowItem(contentItem, collection, environment) { twxlog.Info("shouldShowItem: " + collection.Name + ", " + contentItem.Name); return true; } // Executed once for every collection after the filtering of the items function teardownFilter(collection, environment) { twxlog.Info("teardownFilter: " + collection.Name); }
For the Sample Collection:
// Executed once for every collection before the filtering of the items function setupFilter(collection, environment) { twxlog.Info("setupFilter: " + collection.Name); } // Executed for once for every collection function shouldShowCollection(collection, environment) { twxlog.Info("shouldShowCollection: " + collection.Name); return true; } // Executed for every single content item function shouldShowItem(contentItem, collection, environment) { twxlog.Info("shouldShowItem: " + collection.Name + ", " + contentItem.Name); return true; } // Executed once for every collection after the filtering of the items function teardownFilter(collection, environment) { twxlog.Info("teardownFilter: " + collection.Name); }