Login

Help

Documentation

Advanced Scripting | Sample App 1: Login / Logout Button

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 article first.

    Preview with the Twixl App

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

    The test Entitlement-account you can use to test this behaviour:

    • Username: test
    • Password: test
    deb0efef-8b84-413e-b158-0521031165ab.png

    Use Case

    In this example, we show a Login button in the app when you are not entitled and a Logout button when you are entitled.

    Instructions

    Preparations

    1. Create a new app
    2. Setup Entitlements in the app (e.g. Print Subscribers)
    3. Add a Content Item to the Root Collection with the following properties:
      • Type: Web Link
      • Name: login
      • Link to URL: tp-entitlements-signin://
    4. Add a Content Item to the Root Collection with the following properties:
      • Type: Web Link
      • Name: logout
      • Link to URL: tp-entitlements-clear-token://
    5. Add a Content Item to the Root Collection with the following properties:
      • Type: HTML Article
      • Name: whatever
    6. Set up 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 == "login") {
            return !environment.IsEntitled();
        }
        if (contentItem.Name == "logout") {
            return environment.IsEntitled();
        }
        return true;
    }
    
    // Executed once for every collection after the filtering of the items
    function teardownFilter(collection, environment) {
    }