Skip to content

Commit fbf7d5b

Browse files
Add snippets article
1 parent e9d1d06 commit fbf7d5b

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

articles/static-web-apps/snippets.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
title: Snippets in Azure Static Web Apps (preview)
3+
description: Inject custom code in the HEAD or BODY elements at runtime in Azure Static Web Apps
4+
services: static-web-apps
5+
author: craigshoemaker
6+
ms.service: static-web-apps
7+
ms.topic: overview
8+
ms.date: 06/22/2023
9+
ms.author: cshoe
10+
---
11+
12+
# Snippets in Azure Static Web Apps (preview)
13+
14+
Azure Static Web Apps allows you to inject custom code into the `head` or `body` elements at runtime. These pieces of code are known as "snippets".
15+
16+
Common use cases of snippets include:
17+
18+
- Analytics scripts
19+
- Common scripts
20+
- Global UI elements
21+
22+
## Add a snippet
23+
24+
1. Go to your static web app in the Azure portal.
25+
26+
1. From the *Settings* menu, select **Configuration**.
27+
28+
1. Select the **Snippets** tab.
29+
30+
1. Enter the following settings in the Snippets window:
31+
32+
| Setting | Value | Comments |
33+
|---|---|--|
34+
| Location | Select which element as the destination for your code. | |
35+
| Name | Enter a snippet name. | |
36+
| Insertion location | Select whether you want to **Prepend** or **Append** your code to the selected element. | Prepend means your code appears directly after the open tag of the element. Append means your code appears directly before the close tag of the element. |
37+
| Environment | Select the environment(s) you want to target. | If you select **Select environment** then you can choose a selection of environments to target. |
38+
39+
1. Enter your code in the text box.
40+
41+
1. Select **OK** to close the window.
42+
43+
1. Select **Save** to commit your changes.

0 commit comments

Comments
 (0)