So I have been learning Piranha CMS for .Net Core 3.1.

Having read the docs and studied the template I have hit a bit of wall in getting the information from within Blocks to display on the page correctly.

In the Razor Blog Template on the Page.cs the developer has used the below code to display the Blocks that the page has on screen


@Html.DisplayFor(m => m.Data.Blocks)

On the About Me page on the template website this displays as such:
Image of what should happen

On my own site, I have it written the same and have assigned some simple text blocks to the page to test it, however I get the following: My Site

Can anyone point me in the right direction as to what mistake I might be making?

Both the Startup.cs and other essential files are fine and don’t have any major difference.

The only difference on the site I can see is mine having a lack of styling. But I don’t see why that should affect it.


I’ve answered in the Gitter chat, but I’ll answer here as well if someone else has the same question.

Display templates & Editor templates

The templating system is a built in feature of ASP.NET Core and assumes you have the following folders present in you project.



Razor Pages


Calling templates

When you call DisplayFor() on a collection of objects, like the code you referenced from the Razor Blog template ASP.NET automatically selects the template with the name corresponding to type name. So in this case, if your block is of the type Piranha.Extend.Blocks.TextBlock it will try to locate the view file:


Now if you have your own loop in the view, say if you’d like to add a containing div around every block and give a single object into EditorFor() the standard rendering of ASP.NET will be executed which just prints out the Properties of the given object.

Won’t work the way your want

@foreach (var block in Model.Data.Blocks)
  <div class="myclass">
    @Html.DisplayFor(m => block)


The simple workaround is to just give in the name of the DisplayTemplate that you want to render the block. This can be easily achieved by writing:

@foreach (var block in Model.Data.Blocks)
  <div class="myclass">
    @Html.DisplayFor(m => block, block.GetType().Name)

Best regards