How can I embed GitHub gists into CMS collections using Postscribe in Webflow?

Published on
September 22, 2023

To embed GitHub gists into CMS collections using Postscribe in Webflow, you can follow these steps:

  1. Create a collection: Start by creating a collection in Webflow to store the data for your gists.

  2. Add a field: Add a field to your collection to store the GitHub gist ID. This field will be used to identify the specific gist you want to embed.

  3. Get the GitHub gist embed code: Go to the GitHub gist you want to embed and click on the "Embed" button. Copy the HTML code provided.

  4. Create a custom code block: In your Webflow project, create a custom code block within your CMS collection template. This code block will be used to insert the GitHub gist embed code dynamically.

  5. Install Postscribe: Install the Postscribe library in your Webflow project. You can do this by adding the following code to your custom code block or by linking to the Postscribe script in your project's custom code settings:

    ```html

    ```

  6. Write the JavaScript code: In your custom code block, write JavaScript code that listens for the CMS collection template to load, retrieves the gist ID from the collection item, and then dynamically writes the gist embed code to the custom code block using Postscribe. Here's an example of how the JavaScript code might look:

    ```javascript

    ';

    postscribe('#custom-code-block', gistEmbedCode);
    });

    ```

    Make sure to replace "{{collectionFieldName}}" with the actual name of the field in your collection that stores the GitHub gist ID.

  7. Preview and test: Preview your Webflow project and check that the GitHub gist is successfully embedded into your CMS collection template. Test it by adding different GitHub gist IDs to the collection field and see if the correct gists are displayed.

By following these steps, you should be able to embed GitHub gists into CMS collections using Postscribe in Webflow.