Slices Templating with .NET

Looping through slices

Here is an example of integrating slices into a rich blog post.

@foreach (var slice in document.GetSliceZone("blog-post.body").Value) {
  //- Render the right markup for a given slice type.
  @switch (slice.SliceType) {
    case "text": @: <div>@slice.Value.AsHtml(linkResolver)}</div>
    case "quote": @: <span class='block-quotation'>slice.Value</span>
    case "image-with-caption": @: 
      <p class='block-img'><img src="@slice.Value.Get("illustration").Url"></p>
      <span class='image-label'>@slice.Value.get("caption").AsText()</span>

Was this article helpful?
Not really
Yes, Thanks

Can't find what you're looking for? Get in touch with us on our Community Forum.