Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hi, I'm having trouble with pulling the individual values from the data grid. I can get the full string with both label and value, but i'm new to razor and having trouble.
@widget.featureBlock gives me everything within the datatype.
[ { "blockTitle": "Feature Block 1", "blockParagraph": "Feature Block 1 Content", "blockIcon": "1094", "urlPicker": "1062" }, { "blockTitle": "Feature Block 2", "blockParagraph": "feature Block 2 Content", "blockIcon": "1095", "urlPicker": "1054" } ]
My razor macro is
@{ var widgetsFolder = Model.WidgetsFolders.Where("Visible").First(); } @foreach (dynamic widget in widgetsFolder.Children.Where("Visible and nodeTypeAlias.StartsWith(\"Widget_\")")) { string widgetType = widget.NodeTypeAlias.ToString(); switch (widgetType) { case "Widget_FeatureBlocksReveal": @showFeatureBlocksReveal(widget); break; default: <b>Unknown Widget!</b> break; } } @helper showFeatureBlocksReveal(dynamic widget){ if (!string.IsNullOrEmpty(widget.featureBlock.ToString())) { foreach(dynamic content in widget.featureBlock) { @content.blockTitle } } }
Any help would be grateful.
Martin
Hi Martin.
Which version of umbraco do you use?
Your helper looks fine..
Try to use the example from the project page:
@helper showFeatureBlocksReveal(dynamic widget){ if(!string.IsNullOrEmpty(widget.featureBlock.ToString())) { foreach(var content in widget.featureBlock) { <p>@content.blockTitle</p> } } }
Hi Gilad, thanks for your help.
I tried to use the example razor from package page, but using CurrentPage didnt validate inside the macro and gave the following error.
"error CS0103: The name 'CurrentPage' does not exist in the current context"
@helper showFeatureBlocksReveal(dynamic widget){ if(!string.IsNullOrEmpty(widget.featureBlock.ToString())) { foreach (var content in CurrentPage.widget.featureBlock) { <p>@content.blockTitle</p> } } }
Using the following helper, I am given an error of
"Error loading MacroEngine script (file: RenderWidget.cshtml)"
@helper showFeatureBlocksReveal(dynamic widget){ if(!string.IsNullOrEmpty(widget.featureBlock.ToString())) { foreach (var content in widget.featureBlock) { <p>@content.blockTitle</p> } } }
When I remove the .blockTitle and leave just @content, the macro works, but outputs all the values of the grid data type.
Again, any help would be appreciated. Martin
Edit: Sorry im on the latest version of Umbraco installed through nuget
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Can't Reference Individual Values - Razor Newbie
Hi, I'm having trouble with pulling the individual values from the data grid. I can get the full string with both label and value, but i'm new to razor and having trouble.
@widget.featureBlock gives me everything within the datatype.
[ { "blockTitle": "Feature Block 1", "blockParagraph": "Feature Block 1 Content", "blockIcon": "1094", "urlPicker": "1062" }, { "blockTitle": "Feature Block 2", "blockParagraph": "feature Block 2 Content", "blockIcon": "1095", "urlPicker": "1054" } ]
My razor macro is
Any help would be grateful.
Martin
Hi Martin.
Which version of umbraco do you use?
Your helper looks fine..
Try to use the example from the project page:
Hi Gilad, thanks for your help.
I tried to use the example razor from package page, but using CurrentPage didnt validate inside the macro and gave the following error.
"error CS0103: The name 'CurrentPage' does not exist in the current context"
Using the following helper, I am given an error of
"Error loading MacroEngine script (file: RenderWidget.cshtml)"
When I remove the .blockTitle and leave just @content, the macro works, but outputs all the values of the grid data type.
Again, any help would be appreciated. Martin
Edit: Sorry im on the latest version of Umbraco installed through nuget
is working on a reply...