Skip to content

Latest commit

 

History

History
323 lines (232 loc) · 10.1 KB

File metadata and controls

323 lines (232 loc) · 10.1 KB

Website Blog Email Template

Beta License: AGPL-3 OCA/website Translate me on Weblate Try me on Runboat

This module extends the website blog functionality by allowing you to configure custom email templates for new blog post notifications.

Main Features

  • Custom Email Templates: Configure a custom email template for each blog to personalize notifications
  • Template Selection: Choose from existing mail templates or create new ones specifically for blog notifications
  • Context Access: Templates have access to blog post information through context variables
  • Backward Compatible: If no custom template is configured, the default template is used
  • Link to Post: Templates can include direct links to the published blog post

Benefits

  • Personalize email notifications for different blogs
  • Create branded email templates matching your company style
  • Include additional information in notifications (author, subtitle, etc.)
  • Maintain consistency with your email marketing campaigns
  • Better control over notification content and formatting

Dependencies

This module requires:

  • website_blog: Odoo's website blog module

Table of contents

This module does not require additional configuration after installation. It works automatically once installed.

Installation

  1. Go to the Apps menu
  2. Remove the "Apps" filter if necessary
  3. Search for "Website Blog Email Template"
  4. Click Install

Prerequisites

Make sure the following modules are installed:

  • Website Blog (base blog module)

The system will automatically install the necessary dependencies during installation.

Default Template

After installation, a default custom template is available:

  • Template Name: "Blog: New Post Published (Custom Template)"
  • Location: Settings > Technical > Email > Templates
  • Model: Blog (blog.blog)

You can use this template as-is, customize it, or create new templates based on it.

Permissions

The module uses the same access permissions as the base modules:

  • Users with access to Website and Blogs can configure email templates for blogs
  • Users with access to Settings > Technical > Email > Templates can create and edit email templates

No additional permission configuration is required.

Template Configuration

Template Requirements:

  1. Model: Must be set to "Blog" (blog.blog)
  2. Subject: Can use {{ object.name }} for blog name
  3. Body: HTML content with access to:
    • Blog object: object.name, object.subtitle
    • Post context: ctx.get('blog_post') for post information

Recommended Template Structure:

  • Include a greeting
  • Display blog name
  • Show post title and subtitle
  • Include a link to the post using ctx.get('blog_post').website_url
  • Add a closing message

Usage

This guide explains how to use the Website Blog Email Template module to configure custom email notifications for new blog posts.

Configure a Custom Email Template for a Blog

Step 1: Access Blog Settings

  1. Go to the Website module
  2. Navigate to Blogs > Blogs
  3. Select the blog you want to configure
  4. Open the blog form view

Step 2: Select or Create Email Template

  1. In the blog form, locate the Email Template for New Posts field
  2. You have two options:
    • Option A: Select an existing template from the dropdown
    • Option B: Create a new template (click the search icon and then "Create")

Step 3: Create a New Template (if needed)

  1. Click on the Email Template for New Posts field
  2. Click the search icon (magnifying glass)
  3. Click Create button
  4. Fill in the template form:
    • Name: Give your template a descriptive name (e.g., "Blog Post Notification - Marketing")
    • Model: Should be set to "Blog" (blog.blog)
    • Subject: Email subject line (e.g., "New post: {{ object.name }}")
    • Body: HTML content of the email
  5. Save the template
  6. Select it in the blog's Email Template for New Posts field

Step 4: Save the Blog Configuration

  1. Save the blog form
  2. The custom template will now be used when new posts are published

Using Context Variables in Templates

When creating or editing a template, you can use the following context variables:

Blog Information:

  • {{ object.name }} - Blog name
  • {{ object.subtitle }} - Blog subtitle

Post Information (via context):

  • {{ ctx.get('blog_post').name }} - Post title
  • {{ ctx.get('blog_post').subtitle }} - Post subtitle
  • {{ ctx.get('blog_post').author_name }} - Author name
  • {{ ctx.get('blog_post').website_url }} - Direct link to the post
  • {{ ctx.get('blog_post_id') }} - Post ID

Example Template Body:

<div style="margin: 0px; padding: 0px; font-size: 13px;">
    <p>Hello,<br/><br/>
    A new post has been published on the <strong>{{ object.name }}</strong> blog:<br/><br/>
    <strong>{{ ctx.get('blog_post').name }}</strong><br/><br/>
    <a href="{{ ctx.get('blog_post').website_url }}">Read the full post</a>
    </p>
</div>

Automatic Behavior

Template Selection Logic

When a new blog post is published:

  1. The system checks if the blog has a custom template configured
  2. If a template is configured: Uses message_post_with_template() with the custom template
  3. If no template is configured: Uses the default template (website_blog.blog_post_template_new_post)

Notification Recipients

  • Only blog followers receive the notification
  • The notification uses the subtype "Published Post" (mt_blog_blog_published)
  • Email layout uses "mail.mail_notification_light" for custom templates

Usage Examples

Example 1: Simple Custom Template

  1. Create a blog "Company News"
  2. Create a template with subject: "New article on {{ object.name }}"
  3. Body includes post title and link
  4. Configure the template in the blog
  5. When posts are published, followers receive the custom email

Example 2: Branded Template

  1. Create a blog "Product Updates"
  2. Create a template matching your company branding
  3. Include company logo, colors, and specific formatting
  4. Add additional information like author bio or related posts
  5. Configure in the blog settings

Example 3: Multi-language Support

  1. Create different templates for different languages
  2. Configure language-specific templates per blog
  3. Templates can use language-specific formatting and content

Tips

  • Test your template before publishing posts by using the "Send Test Email" feature in the template
  • Use the default template as a reference when creating custom templates
  • Include the post link (ctx.get('blog_post').website_url) to make it easy for readers to access the content
  • Consider your email client compatibility when designing HTML templates
  • The template is rendered with the blog as object, so use object.name for blog name
  • Post information is available through context, so use ctx.get('blog_post') to access post data

Bug Tracker

Bugs are tracked on GitHub Issues. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us to smash it by providing a detailed and welcomed feedback.

Do not contact contributors directly about support or help with technical issues.

Credits

Authors

  • Escodoo

Contributors

Maintainers

This module is maintained by the OCA.

Odoo Community Association

OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use.

Current maintainer:

marcelsavegnago

This module is part of the OCA/website project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.