A paragraph is a block of content on a page. Editors add paragraphs to the placeholders or grid columns your layout defines, and each paragraph is rendered by a paragraph template in your design.
A paragraph can be one of three things:
- A standard paragraph with a heading, rich text, and an image
- An item-based paragraph with the fields of an item type you define, e.g. a Teaser or an FAQ
- A paragraph with an app attached, e.g. a product list or a login form, where the app renders most of the output with its own templates
The same paragraph template mechanism is used for all three.
Paragraph templates
Paragraph templates live in the Paragraph folder of the design and inherit the ParagraphViewModel:
@inherits Dynamicweb.Rendering.ViewModelTemplate<Dynamicweb.Frontend.ParagraphViewModel>
<section id="p@(Model.ID)" data-dw-colorscheme="@Model.ColorScheme?.Id">
@if (!string.IsNullOrEmpty(Model.Header))
{
<h2>@Model.Header</h2>
}
@if (!string.IsNullOrEmpty(Model.Image))
{
<img src="@Model.Image" alt="@Model.ImageAlt" class="img-fluid">
}
@Model.Text
@Model.GetModuleOutput()
</section>
The properties you use most are:
| Property | Contains |
|---|---|
Header |
The paragraph heading |
Text |
The rich text, as HTML |
Image, ImageAlt, ImageCaption, ImageLink |
The paragraph image and its settings |
Item |
The item fields, if the paragraph is based on an item type, see Item types in templates |
GetModuleOutput() |
The rendered output of the app attached to the paragraph, or an empty string |
ColorScheme |
The color scheme selected on the paragraph, see Styling |
ID, PageID |
The paragraph and page IDs, e.g. for anchors |
If you build all content with item types, most paragraph templates only use Item. Even then, keep a generic Default.cshtml that renders Header, Text, and GetModuleOutput(), so standard paragraphs and app paragraphs always render.
How a paragraph template is chosen
For each paragraph, DynamicWeb uses the first template that applies:
- The template selected on the paragraph by the editor; for item-based paragraphs it is looked up in
Paragraph/{ItemType}/first - For item-based paragraphs, a template mapped to the item type in the website settings,
Paragraph/{ItemType}.cshtml, or a template inParagraph/{ItemType}/ - The
templatesetting of the placeholder the paragraph is in, see Content models Paragraph/Default.cshtml, or the first template in theParagraphfolder
Steps 1 and 3 do not check that the file exists. If a template name is stored on the paragraph or set on the placeholder, DynamicWeb uses it even after the file has been renamed or deleted, and does not continue to the next step. If a paragraph renders wrongly after you rename a template, check the template selected on the paragraph first.
Editors can select any template from the Paragraph folder on a standard paragraph, so the files in the folder are the visual variants they can choose between, e.g. Default, Image left, and Highlight box. Give them names that make sense to editors.
The item types article explains the item-specific steps in detail, including how to offer several layouts for one item type.
Where DynamicWeb looks for the Paragraph folder
DynamicWeb uses the first of these folders that exists:
- A
Paragraphfolder next to the layout, named after it, e.g.Designs/MyDesign/Email/Paragraph/forEmail.cshtml Designs/MyDesign/Paragraph/Designs/Paragraph/, shared by all designs/Files/Templates/Paragraph/
The folders are not merged. If a layout has its own Paragraph folder, editors working on pages with that layout can only choose templates from it, and the default template comes from it too. A template name already stored on a paragraph is the exception: it is looked up file by file, next to the layout, in the design, in Designs/Paragraph/, and in /Files/Templates/Paragraph/, so it can still be found in the design's folder. This is useful when a layout needs completely different markup, as for page-based emails, and a source of confusion when a template "disappears" for pages with one particular layout.
Paragraphs in placeholders and grids
Where paragraphs appear depends on the content model of the layout:
- In a placeholder, all paragraphs are rendered one after another, each with its own paragraph template
- In a grid, each column holds exactly one paragraph, and the row template decides where
column.Output()goes
The paragraph template is the same in both cases. If a template needs to know where it is rendered, GridRowColumnCount, GridColumnNumber, and GridColumnWidth on the ParagraphViewModel tell you about the grid column, and Container tells you the placeholder ID.
Apps in paragraphs
When an app is attached to a paragraph, the app renders its output with templates from its own folder in the design, e.g. eCom/ProductCatalog/. The paragraph template decides where that output goes with @Model.GetModuleOutput(), and can add a wrapper, a heading, or nothing at all.
Apps are documented in Apps, with one article per app describing its templates and ViewModels.