Code Samples
When adding code snippets to the Umbraco documentation, refer to this article for tips on how to improve the samples.
Example
@if (Model.ColorTheme != null)
{
var value = Model.ColorTheme;
<p>@value</p>
}Markdown
{% code caption="HomePageTemplate.cshtml %}
```csharp
@if (Model.HasValue("colorTheme"))
{
var value = Model.Value("colorTheme");
<p>@value</p>
}
```
{% endcode %}Good practices
Define the context
Add a Caption (file name)

Use code comments
Use real-life samples
Add correct syntax highlighting


Add only complete compilable samples
Check for syntax errors
Use File-Scoped Namespaces
With File-Scoped Namespace
Without File-Scoped Namespace
Use line numbers only when relevant

When to use code samples
Types of samples
Inline code

Smaller code snippets

Large code samples
Last updated
Was this helpful?