Search code examples
templatesgridviewrazorumbraco

Using Umbraco 7.2 grid view, how do I insert the grid view into my template?


I'd really like to use grid view to render my content on a simple text page. I've got a grid view with the alias "content" set up. What do I type in the template to get it to show up? @CurrentPage.content does not work. I realize it probably uses those partials that 7.2 came with but I've got no idea how to use them.

It may help to know my knowledge level on this. I'm very new at wiring up templates to doctypes. The only ways of pulling data from my content I actually know how to use so far are these:

  • Get some text by typing something like @CurrentPage.content

  • Get a picture by typing something like @Umbraco.Media(CurrentPage.Picture)


Solution

  • Official documentation for the GridView can be found on the community website. For posterity's sake here is the relevant part:

    Render grid in template

    To display the grid on a site use:

    @CurrentPage.GetGridHtml("propertyAlias")
    

    This will by default use the view /views/partials/grid/bootstrap3.cshtml you can also use the built-in bootstrap2.cshtml view by overloading the method:

    @CurrentPage.GetGridHtml("propertyAlias", "bootstrap2")
    

    or point it a custom view, which by default looks in /views/partials/grid/ - or provide the method with a full path

    @CurrentPage.GetGridHtml("propertyAlias", "mycustomview")
    @CurrentPage.GetGridHtml("propertyAlias", "/views/mycustomfile.cshtml")
    

    If you're working with a strongly typed model simply replace @CurrentPage with @Model.Content, so:

    @Model.Content.GetGridHtml("propertyAlias")