|
| 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