Login

Learning & Support

Documentation

Advanced Scripting | Sample App 3: Using twxlog

Twixl Support Team Updated: - Created :

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.

Preview with the Twixl App

You can preview this app by scanning the QR code with the Twixl app.

Replace QR-Code

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

  1. Create a new app
  2. Enable the Hamburger Menu
  3. Add a content item in the Root Collection with the following properties:
    • Type: Placeholder
    • Name: item-root
    • Title: Root Collection Item
  4. Add a content item in the Hamburger Menu Collection with the following properties:
    • Type: Placeholder
    • Name: item-hamburger
    • Title: Hamburger Item
  5. Add a new Collection with the name Sample Collection
  6. Add a Content Item in the Sample Collection with the following properties:
    • Type: Placeholder
    • Name: item-sample
    • Title: Sample Collection Item
  7. Set up your Advanced Scripting (see below)
  8. Run the app in the Twixl app and then go to the Gear menu > Advanced Filter Log to see the log messages.
  9. 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);
}

Was this article helpful?

0 out of 0 found this helpful