Umbraco & Astro
Este conteúdo não está disponível em sua língua ainda.
Umbraco CMS is an open-source ASP.NET Core CMS. By default, Umbraco uses Razor pages for its front-end, but can be used as a headless CMS.
Integrating with Astro
Section titled Integrating with AstroIn this section you will use Umbraco’s native Content Delivery API to provide content to your Astro project.
Prerequisites
Section titled PrerequisitesTo get started, you will need to have the following:
- An Astro project - If you don’t have an Astro project yet, our Installation guide will get you up and running in no time.
- An Umbraco (v12+) project - If you don’t have an Umbraco project yet, please see this Installation guide.
Setting up the Content Delivery API
Section titled Setting up the Content Delivery APITo enable the Content Delivery API, update your Umbraco project’s appsettings.json
file:
{ "Umbraco": { "CMS": { "DeliveryApi": { "Enabled": true, "PublicAccess": true } } }}
You can configure additional options as needed such as public access, API keys, allowed content types, membership authorisation, and more. See the Umbraco Content Delivery API documentation for more information.
Fetching Data
Section titled Fetching DataUse a fetch()
call to the Content Delivery API to access your content and make it available to your Astro components.
The following example displays a list of fetched articles, including properties such as the article date and content.
---const res = await fetch('http://localhost/umbraco/delivery/api/v2/content?filter=contentType:article');const articles = await res.json();---<h1>Astro + Umbraco 🚀</h1>{ articles.items.map((article) => ( <h1>{article.name}</h1> <p>{article.properties.articleDate}</p> <div set:html={article.properties.content?.markup}></div> ))}
Building a blog with Umbraco and Astro
Section titled Building a blog with Umbraco and AstroPrerequisites
Section titled Prerequisites-
An Astro project - If you don’t have an Astro project yet, our Installation guide will get you up and running in no time.
-
An Umbraco project (v12+) with the Content Delivery API enabled - Follow this Installation guide to create a new project.
Creating blog posts in Umbraco
Section titled Creating blog posts in UmbracoFrom the Umbraco backoffice, create a Document Type for a simple blog article called ‘Article’.
-
Configure your ‘Article’ Document Type with the following properties:
- Title (DataType: Textstring)
- Article Date (DataType: Date Picker)
- Content (DataType: Richtext Editor)
-
Toggle “Allow as root” to
true
on the ‘Article’ document type. -
From the “Content” section in the Umbraco backoffice, create and publish your first blog post. Repeat the process as many times as you like.
For more information, watch a video guide on creating Document Types.
Displaying a list of blog posts in Astro
Section titled Displaying a list of blog posts in AstroCreate a src/layouts/
folder, then add a new file Layout.astro
with the following code:
------<!DOCTYPE html><html lang="en"><head> <meta charset="utf-8"> <title>My Blog with Astro and Umbraco</title></head><body> <main> <slot /> </main></body></html>