Nibble

Advanced Property Editors for Umbraco 7, important detail…

So yesterday I made the matrix prop editor for Umbraco 7 but I forgot an important detail. The prop editor works in the backoffice but when trying to output the values on the frontend I hit an error.

So you would expect this razor snippet to do the trick (in the case we have a prop called matrix)

<table>
<tbody>
@foreach(var row in CurrentPage.matrix)
{
<tr>
@foreach(var val in row)
{
<td>@val</td>
}
</tr>
            }
</tbody>
</table>

 

But when trying that I got the error Cannot implicitly convert type ‘char’ to ‘System.Collections.IEnumerable’

Since razor thought the data was a string…

To make sure razor knows the prop editor is storing json update the manifest to include the value type (standard it’s set to string)

editor: {
        view: "~/App_Plugins/MatrixEditor/matrixeditor.html",
        valueType: "JSON"
        },

More info on the options in the manifest can be found here http://umbraco.github.io/Belle/#/tutorials/manifest

So changing that makes the razor snippet work and I get the following output

<table>
<tbody>
<tr>
<td>1</td>
<td>2</td>
</tr>
<tr>
<td>3</td>
<td>4</td>
</tr>
<tr>
<td>5</td>
<td>6</td>
</tr>
<tr>
<td>7</td>
<td>8</td>
</tr>
</tbody>
</table>

 

When the content editor inputs

image

5 Comments so far

  1. Florian on November 19th, 2013

    Sweet. So the property doesn’t have to a a single value?

    If I say $scope.model.value = {
    name:’John’, lastName:’Doe’, Age:40
    };
    In my own property editor.
    Razor will pick it up as:
    @Property.name , @Property.lastname, … ?
    With intellisense in Visual Studio?

  2. Tim Geyssens on November 19th, 2013

    @Florian yes :) check Per’s Sir Trevor demo! For intellisense you’ll need a property editor convertor (to go strongly typed)

  3. Tim Geyssens on November 19th, 2013

    @Florian, details on those convertors here http://www.slideshare.net/JeavonLeopold/what-theheck
    Will do a follow up blog post!

  4. Tim Geyssens on November 19th, 2013

    @Florian but looks like the v7 thing to use is PropertyValueConverter

  5. Yarik on December 1st, 2013

    Hi.
    We can i find Per’s Sir Trevor demo?
    Thanks,
    Yarik

Leave a Reply