Skip to content

Commit 7b77a54

Browse files
Sofie Toft Kristensengitbook-bot
authored andcommitted
GITBOOK-8: Customizing Templates
1 parent 4432e39 commit 7b77a54

File tree

3 files changed

+76
-0
lines changed

3 files changed

+76
-0
lines changed
Binary file not shown.

15/umbraco-commerce/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
* [Add item to Cart](how-to-guides/add-item.md)
3636
* [Update Cart](how-to-guides/update-cart.md)
3737
* [Delete item from Cart](how-to-guides/delete-item.md)
38+
* [Customizing Templates](how-to-guides/customizing-templates.md)
3839

3940
## Key Concepts
4041

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
---
2+
description: Learn how to create custom templates for emails, prints, and exports.
3+
---
4+
5+
# Customizing Templates
6+
7+
Umbraco Commerce provides support for customizing templates for emails, prints, and exports. This allows you to tailor the outputs of your e-commerce solution to meet specific branding or functional requirements.
8+
9+
## Accessing the Default Built-in Templates
10+
11+
The default templates for email, print, and export are embedded in Razor Class Libraries (RCLs) in Umbraco Commerce. To customize these templates, you can extract them and use them as a starting point.
12+
13+
Download the custom templates and place them in `/Views/Partials/Commerce/Email/`.
14+
15+
{% file src="../.gitbook/assets/Umbraco.Commerce.Templates.v15.zip" %}
16+
Umbraco Commerce Custom Templates
17+
{% endfile %}
18+
19+
## Creating Custom Templates
20+
21+
### Email Templates
22+
23+
To Create a Custom Email Template:
24+
25+
1. Create a Razor view file (`.cshtml`) in `/Views/Partials/Commerce/Email/.`
26+
2. Implement the `IEmailTemplate` interface to make the template available in Umbraco Commerce:
27+
28+
```csharp
29+
using Umbraco.Commerce.Core.Interfaces;
30+
31+
public class CustomOrderEmailTemplate : IEmailTemplate
32+
{
33+
public virtual string FileName => "CustomOrderEmail.cshtml";
34+
}
35+
36+
```
37+
38+
3. Register the Template in a Composer:
39+
40+
```csharp
41+
using Umbraco.Cms.Core.Composing;
42+
using Umbraco.Cms.Core.DependencyInjection;
43+
44+
public class CustomTemplateComposer : IComposer
45+
{
46+
public void Compose(IUmbracoBuilder builder)
47+
{
48+
builder.EmailTemplates().Add<CustomOrderEmailTemplate>();
49+
}
50+
}
51+
52+
```
53+
54+
### Print and Export Templates
55+
56+
To create Print/Export Templates:
57+
58+
1. Create a Razor view file (`.cshtml`) under the relevant paths:
59+
60+
```
61+
/Views/Partials/Commerce/Prints/
62+
/Views/Partials/Commerce/Exports/
63+
```
64+
65+
2. Implement the `IPrintTemplate` or `IExportTemplate` interface to make the template available in Umbraco Commerce.
66+
3. Register the template in a Composer similar to the email template process.
67+
68+
## Shipping Custom Templates in a Razor Class Library
69+
70+
To distribute custom templates as part of a Razor Class Library (RCL):
71+
72+
1. Create a new Razor Class Library project.
73+
2. Add the template files under appropriate paths, for example, `Views/Partials/Commerce/Emails/`.
74+
3. Implement interfaces like `IEmailTemplate,` `IPrintTemplate,`or `IExportTemplate` .
75+
4. Use a composer to register your custom templates.

0 commit comments

Comments
 (0)