# Global Snippets
A snippet is a reusable piece of code that modularizes and breaks down complex functionalities into simpler parts. Global snippets are dynamically rendered when the page loads.
Global snippets in Modyo allow you to share code between your different web applications.
Shared Code
A change in a global snippet affects all web applications where it is used. Therefore, only users with an administrator role can access global snippets.
In the snippet editing view, you can create and manage your global snippets. The top bar offers the following options:
- Differences: Allows you to compare changes between multiple versions of a snippet, select 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 your snippet is saved, this button changes status to publish.
The following sections are above the work area:
- Media
- Keyboard shortcuts
- Snippets: List of previously created snippets.
- Changes: List of previously saved versions.
# Create and Publish a Global Snippet
To create and publish 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 an unpublish date, if desired.
# Load 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 directly 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/snippet_name
. - 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 desired.
# Preview a Snippet
To preview a global snippet in your web application:
- In the side menu, click Channels.
- Select your web application.
- Select Widgets or Templates (if you select Templates, go directly 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 view. Global snippets always use the nomenclature
global/snippet_name
. - 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 edit. Global snippets always use the nomenclature
global/snippet_name
. - Modify the snippet as required.
- Click Save.
- Click Publish.
- Select whether you want to publish your global snippet immediately or on a specific date. You can also select an unpublish date, if desired.
Immediate Publication
Making changes to a global snippet affects all web applications where it is published. Proceed with caution before editing or deleting a snippet.