Security News
Supply Chain Attack Detected in Solana's web3.js Library
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
react-email-shopify-liquid
Advanced tools
Create shopify notification emails with a combination of React and Liquid
Create shopify notification emails with a combination of React and Liquid
You are building a headless ecommerce experience using shopify. Probably with Hydrogen, Remix, NextJS, etc.
You've built a set of composoble components using React, however there is one critical piece that is missing: Email Notifications. Emails for Order confirmation, shipping, etc.
You'll need to use Shopify's Liquid to build all of your email templates, which is a completely different developer experience than React.
We've build a set of components using React Email to help you create beautiful email templates. Helping consolidate the developer experience when creating headless shopify store.
In your project directory:
Install: pnpm add react-email @react-email/components react-email-shopify-liquid -E
Create an emails
folder at the top level of your project directory.
Create a file named OrderConfirmation.tsx
and paste the following:
This template is from
examples/emails/OrderConfirmation.tsx
:
import React from 'react';
import { Hr, Preview, Section, Text } from '@react-email/components';
import { EmailContainer, Greeting, OrderLineItems, OrderStatusLink, OrderTransactions, PaymentTerms, ShippingAddress, Subtotals } from 'react-email-shopify-liquid';
export const OrderConfirmation = () => (
<EmailContainer>
<Preview>Order Confirmation</Preview>
<Section>
<Greeting />
<Text>
Thank you for placing your order ({'{{ order.name }}'}). As soon as your order ships, you will receive a separate shipping confirmation email with tracking information.
</Text>
</Section>
<Section className="mt-6">
<OrderStatusLink />
</Section>
<Hr className="border-black my-10"></Hr>
<OrderLineItems />
<Subtotals />
<Hr className="border-black my-10"></Hr>
<PaymentTerms />
<OrderTransactions />
<ShippingAddress />
</EmailContainer>
);
export default OrderConfirmation;
Add the following script to your package.json
which will generate the email template html files
"email:export": "email export && decode-entities"
This package includes a simple
decode-entities
bin script. React will encode things like quotes and>
,<
, which might be used within liquid expressins into html entites. Hence we need to decode those for liquid to render properly.
Example:
Payment of {{ order.total_outstanding | money }} is due {{ due_date | date: format: 'date' }}
will becomePayment of {{ order.total_outstanding | money }} is due {{ due_date | date: format: 'date' }}
once decoded.
If you have a more complex workflow, create your own script to handle decoding the html files.
#!/usr/bin/env node
import { readFileSync, writeFileSync } from 'fs';
import path from 'path';
import { glob } from 'glob';
import { decode } from 'html-entities';
// React will encode quotes and etc that might be used within liquid expressions into entites.
// Hence we need to decode those for liquid to render properly
export const decodeEntities = () => {
const generatedEmailPaths = glob.sync(path.join(process.cwd(), 'out', '**/*.html'))
for (const emailPath of generatedEmailPaths) {
const html = decode(readFileSync(emailPath, { 'encoding': 'utf-8' }));
writeFileSync(emailPath, html, { encoding: 'utf-8' });
}
};
decodeEntities();
Run the script pnpm run email:export
. And look in the new folder out
that was created.
out
at the root level of your project. All of the generated html files for your email templates will be placed here. See react-email documentation for more information on the email export
command. The default source directory for your templates is emails
.Let's preview the email template: Head over to the shopify admin page.
Click on the Settings
⚙️ icon
Select the Notifications
menu item
Click on the Customer Notifications
menu item
Select the Order Confirmation
notification
Hit the Edit Code
button
Paste the generated html from OrderConfirmation.html
into the textarea
Preview your changes and hit save.
Can I preview my email templates with react-email's
email:dev
script? Yes, but it won't be that helpful. Since the templates include liquid template syntax for retrieving like order details, line items, product information, we need these objects provided to us.
Shopify's email template preview functionality will actually render your email template using the liquid template engine and provide all the relevant objects like
order
,product
, etc. Theemail:dev
script would just render the raw liquid syntax.
That's it. Now, repeat for the rest of your email templates! Head over to examples/emails
to see more templates.
If you take a look at the default shopify email templates available in shopify admin, you'll see there is a lot of logic involved. Not every single piece of logic is ported over to this package. If any custom logic is required, just create your own component using our provided Liquid
components. See the example templates for how this can be done.
FAQs
Create shopify notification emails with a combination of React and Liquid
The npm package react-email-shopify-liquid receives a total of 13 weekly downloads. As such, react-email-shopify-liquid popularity was classified as not popular.
We found that react-email-shopify-liquid demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.