ℹ️ Email newsletter templates

When Micro.blog sends an email newsletter to your subscribers, it runs your posts through a special template to produce the HTML for the email. You can see the source of the default template here on GitHub.

The template uses a syntax with {{ }} for inserting values into the email, similar to the syntax used in Hugo for publishing your blog. For example, to add the intro text for a newsletter, the HTML would look like this:

{{ .Intro }}

The following variables are available in the newsletter template:

  • .Site.Title: Your blog’s title.
  • .Site.Author.avatar: URL for your profile photo.
  • .Site.Author.name: Your name.
  • .Site.BaseURL: The URL for your blog.
  • .Site.Hostname: Just the hostname for your blog.
  • .Subject: The email subject.
  • .Intro: The optional intro text for the email. This can be set when editing a queued newsletter.
  • .CustomCSS: CSS set from Design → Edit CSS, if the checkbox is checked to use it in email newsletters.
  • .Footer.MailingAddress: The optional mailing list, set in Newsletters → Settings. This is usually included in the footer.
  • .Footer.UnsubscribeURL: URL to unsubscribe. This URL includes the subscriber’s email address for convenience.
  • .Pages: An array of blog posts. Each post has these fields:
    • .Title: The blog post title if not a short microblog post.
    • .Content: HTML for the blog post.
    • .Plain: Text version of the blog post with HTML tags removed.
    • .Summary: Text of the first 500 characters or everything before the <!--more--> comment if present. If using <!--more-->, value will be HTML.
    • .Permalink: URL for the blog post.
    • .Date: Published date for the blog post. You can add a format string like .Date.Format "2006-01-02".
    • .Params: Some additional blog post fields, currently .categories, .audio, and .video URL arrays.

Plug-ins can provide their own templates by including a file layouts/newsletter.html. Your own custom template (set under Newsletters → Settings) will be used first if you’ve set it. To revert to a plug-in’s template or Micro.blog’s default template, you can clear the text for your custom template in the settings.

Note that while the template looks very similar to Hugo templates, Hugo itself is not used for processing email newsletters. There will be some features available in Hugo that are not available in email templates.

2 Likes