Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Howard 87 posts 35 karma points
    Feb 23, 2015 @ 20:51
    Howard
    0

    Strongly Typed Grid Data Access for Macro Parameters

    Hi,

    I have implemented skybrud.Umbraco.GridData for Strongly Typing the Grid Editor which was going fine.. but. I have access to all the values from the Grid Json output but I want to include Macros within the grid.

    In the Json the macro data outputs like this:

    "value": {

                        "macroAlias": "SomeWidget",

         "macroParamsDictionary": {

                          "Headline": "Widget Headline",

                          "Link": "1102",

                          "SubHeadline": "Call to Action"

     

                        }

    After a number of foreach loops to iterate through sections, rows, areas and finally controls, there are no properties to access the macro parameters and control.Value just outputs

    Skybrud.Umbraco.GridData.Values.GridControlMacroValue

    with no more poperties available.

    Help would be much apreaciated! thanks. Howard

    Umb v7.2.2 using VS2013

  • Anders Bjerner 487 posts 2989 karma points MVP 8x admin c-trib
    Feb 23, 2015 @ 22:26
    Anders Bjerner
    1

    Hi Howard,

    Sorry for the lack of documentation. I simply haven't had the time for it :(

    Do you have an example of what your code looks like? From what I can tell you're trying to use the Value property on the macro control. The type of property depends on the control, so for a macro control it is of the type GridControlMacroValue. You can use something like this:

    if (control.Editor.Alias == "macro") {
    
        GridControlMacroValue value = control.GetValue<GridControlMacroValue>();
    
        if (value.MacroAlias == "TestMacro") {
    
            Console.WriteLine("URL: " + value.Parameters["Url"]);
    
        }
    
    }
    
  • Howard 87 posts 35 karma points
    Feb 24, 2015 @ 13:31
    Howard
    0

    Hi, Thanks for the quick response.

    Yes, I was trying to access the value. I tried GetValue but didnt pass it a Type as per your documentation so it didn't work. What i ended up doing was getting the control as a JObject and accessing the Tokens to get the data. Your solution is much more precise, thanks!

    JObject obj = control.JObject;

     

    var valueToken = obj.SelectToken("value");

    if (valueToken.SelectToken("macroAlias") != null){

    var macroAlias = valueToken.SelectToken("macroAlias");

    var macroParams = valueToken.SelectToken("macroParamsDictionary");

    @Html.Partial("~/Views/Partials/Widgets/_CTA.cshtml", macroParams)

     

    }

    Do you have an example of how you would replace the Grid Editor Bootstrap 3 convertor? I have done a version but i don't want to do all the code in the view.

    I would prefer to create some Helper methods that output the HTML so I can store in a model and pass to the relevant views and Partials. I have a number of widgets that are both sitewide and local to the page. The intention is to use the gridEditor to select and organise the approriate widgets and populate with data/prefs; then the controller will call the Grid renderer method(using Skybrud.GridData), insert the widget code (pulled from templates) and output the html to the view. Templates could just be HTML with {{value}} tokens that get replaced by the method OR partial views that get passed the Jtoken macro parameters. 

    Do you think this is feasable or am i over complicating? Am i asking too much from the GridEditor? Due to the site being fully responsive and some widges using ajax/jquery, Depending upon certain parameters that the editor selects for the widget, I need to control the parent classes and markup so rendering the page output HTML before passing to the view gives more control. Any guidance would be apreciated.

    Many thanks! Howard

  • Anders Bjerner 487 posts 2989 karma points MVP 8x admin c-trib
    Feb 24, 2015 @ 18:42
    Anders Bjerner
    0

    Hi again,

    I don't have an example on how to render the Grid in frontend using the strongly typed model, since I actually haven't had to use it myself yet. The strongly typed model was created as a proof of concept for indexing the Grid in Examine.

    I'll see whether I can dig up some examples ;)

  • Howard 87 posts 35 karma points
    Feb 25, 2015 @ 23:16
    Howard
    0

    Hi Anders,

    Thanks for the reply. An example or two would be great thanks, I am currently coding the UI Templates for the site so once complete would be good to share once I have integrated with the grid. I have Recompiled Bootstrap stripped down to just the core grid and base utilites so it will be a useful example. Thanks!

    Getting the grid to work with examine will be the next thing! good work!

    Howard :)

Please Sign in or register to post replies

Write your reply to:

Draft