In this tutorial, we’ll use Events in Maizzle to fetch the contents of an RSS feed and display them in an HTML email newsletter. You can preview the final result on CodePen.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/maizzle/maizzle.com/llms.txt
Use this file to discover all available pages before exploring further.
Initial setup
Let’s start by creating a new Maizzle project../example-rss, and select the Default Starter.
Choose Yes when prompted to Install dependencies.
Once it finishes installing dependencies, open the project folder in your favorite editor.
rss-parser
We’ll be using rss-parser fetch the contents of the RSS feed, so let’s install it:RSS Feed
We’ll need an RSS feed to work with, so let’s go with the best site for learning Laravel. The Laracasts feed is available at https://laracasts.com/feed. Let’s add that feed URL inside thebuild object in config.js:
config.js
Fetch Items
We can userss-parser inside the beforeCreate event to fetch feed data.
Edit config.js, require rss-parser, and use it in the beforeCreate event:
config.js
The Laracasts feed contains fields that
rss-parser does not currently return by default. We include them through the customFields option.Date Format
We’ll probably need to format the date of a feed item to something more readable than what the feed provides. We can add a function toconfig.js and use it to format the item’s date according to our audience’s locale:
config.js
Tip: you could set
'en-US' dynamically, based on your subscriber’s preference.Template
We’ll use a simplified version of the promotional template from the Starter, displaying posts as full width cards.Header
Let’s update the existing header row:emails/promotional.html
Items Loop
Let’s use a full width card from the promotional template to show a list of all items from the feed:emails/promotional.html
npm run build to generate the production-ready email template.
Take a look at the final result on CodePen.
Resources
- Laracasts
- rss-parser
- Maizzle Events
- GitHub repository for this tutorial
- CodePen preview