From b88aef559cd93cc539cf6cf7c119d82e4bb359d2 Mon Sep 17 00:00:00 2001 From: Matthew Phillips Date: Thu, 22 Sep 2022 11:28:22 -0400 Subject: [PATCH] Document new types for set:html (#1599) Co-authored-by: Yan Thomas <61414485+Yan-Thomas@users.noreply.github.com> Co-authored-by: Sarah Rainsberger Co-authored-by: Chris Swithinbank --- .../en/reference/directives-reference.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/pages/en/reference/directives-reference.md b/src/pages/en/reference/directives-reference.md index b33e46ff102fac..1b45696222b795 100644 --- a/src/pages/en/reference/directives-reference.md +++ b/src/pages/en/reference/directives-reference.md @@ -67,6 +67,25 @@ const cmsContent = await fetchHTMLFromMyCMS(); ``` +`set:html={Promise}` injects an HTML string into an element that is wrapped in a Promise. + +This can be used to inject HTML stored externally, such as in a database. + +```astro +--- +import api from '../db/api.js'; +--- +
+``` + +`set:html={Promise}` injects a [Response](https://developer.mozilla.org/en-US/docs/Web/API/Response) into an element. + +This is most helpful when using `fetch()`. For example, fetching old posts from a previous static-site generator. + +```astro +
+``` + ### `set:text` `set:text={string}` injects a text string into an element, similar to setting `el.innerText`. Unlike `set:html`, the `string` value that is passed is automatically escaped by Astro.