# 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:
- In the side menu, click channels.
- Click on snippets.
- Click on the + button next to global in the right column.
- Enter your code.
- Click save.
- Click publish.
- 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:
- In the side menu, click channels.
- Select your web application.
- Select widgets or templates (if you select templates, go to step 5).
- Select your widget.
- Click on the snippets tab, above the work area, to display the list of available global snippets.
- Select the global snippet you want to use. Global snippets always use the nomenclature
global/nombredelsnippet
. - Click publish.
- 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:
- In the side menu, click channels.
- Select your web application.
- Select widgets or templates (if you select templates, go to step 5).
- Select your widget.
- Click on snippets, above the work area, to display the list of available snippets.
- Select the snippet you want to use. Global snippets always use the nomenclature
global/nombredelsnippet
. - Click on the preview icon.
# Edit a snippet
To modify a snippet, follow these steps:
- In the side menu, click channels.
- Click on snippets.
- Select the snippet you want to use. Global snippets always use the nomenclature
global/nombredelsnippet
. - Modify the snippet as needed.
- Click save.
- Click publish.
- 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.