Copied to clipboard

Flag this post as spam?

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


  • mcgrph 35 posts 162 karma points
    Oct 31, 2019 @ 07:04
    mcgrph
    0

    Access custom app plugin data in IPublishedContent context

    I was wondering if there is an easy way to access the data (if available) of a custom plugin, which was added to the content of a page. So in my base template I would invoke my html action with something like this

    @Html.Action("MethodName", "ControllerName", new { node = CurrentPage })
    

    In my controller I would like to first check if a custom plugin is added to this specific page and if so get the data of this plugin.

    I know that it's stored somewhere in node.Properties.Value (as IPublishedContent) but I assume there must be an easier way to access this. Unfortunately I didn't find anything in the official documentation.

    Perhaps someone can point me in the right direction?

  • mcgrph 35 posts 162 karma points
    Oct 31, 2019 @ 07:22
    mcgrph
    0

    I've found this post: https://our.umbraco.com/forum/using-umbraco-and-getting-started/79220-get-a-members-custom-property but I'm not sure if this fits my needs. When I try to implement it, it always returns null.

  • mcgrph 35 posts 162 karma points
    Oct 31, 2019 @ 08:09
    mcgrph
    0

    Ok, so I think I found a workaround:

        var editor = node.GetProperty("asideContent");
    
        if (editor != null)
        {
            var editorString = editor.Value.ToString();
    
            if (editorString.Contains("APP_PLUGIN_ALIAS"))
            {
                var parsed = JObject.Parse(editor.Value.ToString());
                var controls = parsed["sections"][0]["rows"][0]["areas"][0]["controls"];
    
                if (controls.First != null)
                {
                    foreach (var item in controls.Children())
                    {
                        var alias = item["editor"]["alias"].ToString();
    
                        if (alias != null && alias == "APP_PLUGIN_ALIAS")
                        {
                            var element = JsonConvert.DeserializeObject<CUSTOM_MODEL>(item["value"].ToString());
                        }
                    }
                }
            }
        }
    
  • mcgrph 35 posts 162 karma points
    Oct 31, 2019 @ 10:19
    mcgrph
    0

    Still not really working though, because I have to know in which property the plugin is added ...

Please Sign in or register to post replies

Write your reply to:

Draft