1

I am using Craft as a headless CMS and have set base Url/siteUrl to the url of my React/Gatsby site.

I needed to do this as my navigation plugin, Navie, appends it by default.

But now when users registers, they are sent an activation email with the Gatsby url.

How can I change this?

Thanks

1 Answer 1

2

You can use a Twig replace filter in the email template to replace the URL with whatever you like. (I'm using this method myself because we have a similar problem on multi-site installs). To do this you'll need to be using custom templates for all system emails: Settings > Email > HTML Email Template

I'd set that to something like emails/index, which could then be like this, routing out to separate template files depending on the emailKey:

{# Craft has four predefined email keys: account_activation verify_new_email forgot_password test_email ... route to them here, or fallback to default #} {% include [ 'emails/' ~ emailKey ?? null, 'emails/default' ] %} 

Then emails/account_activation.twig could be something like this using the replace filter on the link variable:

{% extends 'emails/_emailLayout' %} {% set lockscreenText = 'Activate your account' %} {%- set heading -%} Hi {{ user.friendlyName ?? 'there' }}, {%- endset -%} {% block content %} <p>Your account is now set up and ready to use, with your email address as your username.</p> <p>To activate your account, click the following link:</p> {% endblock %} {% if link is not defined %} {% set link = 'http://local.test' %} {% endif %} {% set buttonLink = link|replace('https://old.com/actions','https://new.com/actions') %} {% set buttonText = 'Activate your account' %} 

...while emails/_emailLayout would have all the complicated mess of HTML that cross-client email requires.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.