# Global snippets

A snippet is a small piece of reusable code. Snippets are useful for modularizing and reusing functions, breaking down complex functionality into simpler parts. In addition, they are dynamically rendered when the page loads.

Global snippets in Modyo allow you to share code between your different web applications.

Tip

A change in a global snippet affects all the web applications where it is being used, therefore only users with an administrator role can access the global snippets.

In the snippet editing view, you can create and manage your global snippets. In the top bar, you have the following options:

  • Differences: Allows you to compare changes between multiple versions of a snippet. You can select the versions to compare and reset or rollback to previous versions.
  • Other actions:
    • Archive: To archive a snippet you must first publish it.
    • Delete: To delete a snippet you must first archive it.
  • Save: Once you've saved your snippet, this button changes status to publish.

The sections that can be found above the work area are:

  • Media
  • Keyboard shortcuts
  • Snippets: List of previously created snippets.
  • Changes: List of previously saved versions.

# Create and publish a global snippet

To create a global snippet, follow these steps:

  1. In the side menu, click channels.
  2. Click on snippets.
  3. Click on the + button next to global in the right column.
  4. Enter your code.
  5. Click save.
  6. Click publish.
  7. Select whether you want to publish your global snippet immediately or on a specific date. You can also select a unplublish date, if you wish.

# Upload a global snippet

To load and use a previously created global snippet:

  1. In the side menu, click channels.
  2. Select your web application.
  3. Select widgets or templates (if you select templates, go to step 5).
  4. Select your widget.
  5. Click on the snippets tab, above the work area, to display the list of available global snippets.
  6. Select the global snippet you want to use. Global snippets always use the nomenclature global/nombredelsnippet.
  7. Click publish.
  8. Select whether you want to publish the global snippet immediately or on a specific date. You can also select an unpublish date, if you wish.

# Preview a snippet

To preview a global snippet in your web app:

  1. In the side menu, click channels.
  2. Select your web application.
  3. Select widgets or templates (if you select templates, go to step 5).
  4. Select your widget.
  5. Click on snippets, above the work area, to display the list of available snippets.
  6. Select the snippet you want to use. Global snippets always use the nomenclature global/nombredelsnippet.
  7. Click on the preview icon.

# Edit a snippet

To modify a snippet, follow these steps:

  1. In the side menu, click channels.
  2. Click on snippets.
  3. Select the snippet you want to use. Global snippets always use the nomenclature global/nombredelsnippet.
  4. Modify the snippet as needed.
  5. Click save.
  6. Click publish.
  7. Select whether you want to publish your global snippet immediately or on a specific date. You can also select a publication date, if you wish.

Danger

Making changes to a global snippet affects all web applications where the snippet is published, so proceed with caution before editing or deleting a snippet.