Snippets

Snippets are, well, little snippets of code which are rendered last. In practical terms, this means that a snippet is used for moving contextual data from e.g. a ProductDetails template and into the master template where it would not normally be available.

One common usecase is that you want to add product data to the Open Graph metadata tagsv in a master template, making it possible for Facebook to read the title and image of a product being shared, for instance.

First define a snippet:

RAZOR
@SnippetStart("mySnippet") ..some code to move... @SnippetEnd("mySnippet")

Then render the snippet elsewhere:

RAZOR
@RenderSnippet("mySnippet")