kgiszewski / Archetype

Archetype is an Umbraco 7 property editor that wraps other installed property editors.
https://github.com/kgiszewski/ArchetypeManual
MIT License
89 stars 54 forks source link

Passing an Archetype as a macro parameter #215

Closed outcome closed 8 years ago

outcome commented 10 years ago

Hi, thanks for an awesome package :-) We use it a lot in our Umbraco systems and so far only have good things to say. However, I do have a question/feature request. Is it possible to pass an Archetype in as a macro parameter? What I'm trying to do is use Archetype for front page widgets and I have a switch case where the code shows different HTML for different widget types (based on the alias). Then one of my widgets has a nested Archetype and I've been trying to use JsonConvert.DeserializeObject<ArchetypeModel> on the string that gets passed to the macro but I always get a conflict with other property editors like the uWestFest Url Picker. Is there a way to tell the macro parameter to expect an Archetype or call the Archetype Value Converter directly?

This is the code I have:

    switch(boxAlias) {
        case "linkBox":
             var boxlinks = box.GetValue("boxLinks");
             @Umbraco.RenderMacro("Quicklinks", new {links = boxlinks})
             break;
    }

And then in the Quicklinks macro I have:

    var links = Model.MacroParameters["links"].ToString();

    ArchetypeModel linksModel = JsonConvert.DeserializeObject<ArchetypeModel>(links);
    foreach(ArchetypeFieldsetModel link in linksModel) {
        @link.GetValue("linkIcon")
    }

This gives me a null reference error coming from the IsConverter() method of the uWestFest Url picker. Am I doing something wrong or is this just not possible?

Thank you so much, Sunnefa @ Outcome Software

kgiszewski commented 10 years ago

The bad news is I don't use macros anymore so I can't give you much help.

It would appear the PVC are getting called.

Can you confirm the type of 'links' is a string and not something else? (i.e. UrlPicker)

outcome commented 10 years ago

The nested Archetype has three properties, title, icon and url. The url property uses the UrlPicker property editor. The links variable in the macro is indeed a string and everything works right up until this part:

    @link.GetValue("linkIcon")

If I write:

    @link.Alias

everything works just fine. So it seems to have something to do with a property value converter. I ended up just looping over the links in the switch case instead of calling a macro to do it, but that of course ends up making my code a bit cluttered. Do you have any other suggestions as to how I could achieve this functionality? Thank you, Sunnefa

kgiszewski commented 10 years ago

Could you try doing explicit gets?

@link.GetValue<string>("linkIcon")

outcome commented 10 years ago

No, I just tried it and it makes no difference, I still get a null reference error from the Url picker...

BenFidge commented 8 years ago

Out of interest, how did you get archetype to work using it as a macro parameter? I tried adding a package.manifest with isParameterEditor set to ttrue, and it appears in the macro parameter type drop-down list, but selecting it doesnt do anything?

kgiszewski commented 8 years ago

This isn't something we're planning to support.