Copied to clipboard

Flag this post as spam?

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


  • M T 35 posts 212 karma points
    Nov 08, 2016 @ 16:27
    M T
    0

    Output data from a content picker via a macro

    So I've created some content nodes that have one RTE datatype called 'content', these nodes are going to be treated as reusable widgets so I'd like users to be able to pick the nodes from a content picker(macro) and then the data in the RTE will be output on the front-end. The macro will be mainly used in the grid editor, the picker works I'm just having trouble outputting content from the picked node.

        @inherits Umbraco.Web.Macros.PartialViewMacroPage
    
    @{
        @*get the picked node from the content picker*@
        var node = Umbraco.Content(CurrentPage.picker);
    
        @*output the data stored in the 'content' datatype*@
        @node.content;
    
    }
    

    Gives this error where the content would be rendered :-

        Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: The call is ambiguous between the following methods or properties: 'Umbraco.Web.UmbracoHelper.Content(params int[])' and 'Umbraco.Web.UmbracoHelper.Content(params string[])'
       at CallSite.Target(Closure , CallSite , UmbracoHelper , Object )
       at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
       at ASP._Page_Views_MacroPartials_widgetRender_cshtml.Execute() in c:\DignityFiles\Simplicity\Simplicity\Views\MacroPartials\widgetRender.cshtml:line 6
       at System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
       at System.Web.Mvc.WebViewPage.ExecutePageHierarchy()
       at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
       at System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance)
       at System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer)
       at Umbraco.Core.Profiling.ProfilingView.Render(ViewContext viewContext, TextWriter writer)
       at Umbraco.Web.Mvc.ControllerExtensions.RenderViewResultAsString(ControllerBase controller, ViewResultBase viewResult)
       at Umbraco.Web.Macros.PartialViewMacroEngine.Execute(MacroModel macro, IPublishedContent content)
       at Umbraco.Web.Macros.PartialViewMacroEngine.Execute(MacroModel macro, INode node)
       at umbraco.macro.LoadPartialViewMacro(MacroModel macro)
       at umbraco.macro.renderMacro(Hashtable pageElements, Int32 pageId)
       at Umbraco.Web.UmbracoComponentRenderer.RenderMacro(macro m, IDictionary`2 parameters, page umbracoPage)
       at Umbraco.Web.UmbracoComponentRenderer.RenderMacro(String alias, IDictionary`2 parameters, page umbracoPage)
       at Umbraco.Web.UmbracoComponentRenderer.RenderMacro(String alias, IDictionary`2 parameters)
       at Umbraco.Web.UmbracoHelper.RenderMacro(String alias, IDictionary`2 parameters)
       at ASP._Page_Views_Partials_grid_editors_macro_cshtml.Execute() in c:\DignityFiles\Simplicity\Simplicity\Views\Partials\Grid\Editors\Macro.cshtml:line 15
       at System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
       at System.Web.Mvc.WebViewPage.ExecutePageHierarchy()
       at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
       at System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance)
       at System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer)
       at Umbraco.Core.Profiling.ProfilingView.Render(ViewContext viewContext, TextWriter writer)
       at System.Web.Mvc.HtmlHelper.RenderPartialInternal(String partialViewName, ViewDataDictionary viewData, Object model, TextWriter writer, ViewEngineCollection viewEngineCollection)
       at System.Web.Mvc.Html.PartialExtensions.Partial(HtmlHelper htmlHelper, String partialViewName, Object model, ViewDataDictionary viewData)
       at System.Web.Mvc.Html.PartialExtensions.Partial(HtmlHelper htmlHelper, String partialViewName, Object model)
       at ASP._Page_Views_Partials_grid_editors_base_cshtml.Execute() in c:\DignityFiles\Simplicity\Simplicity\Views\Partials\Grid\Editors\Base.cshtml:line 20
    

    first time using macro's in Umbraco, any pointers would be appreciated. Maybe theres a better way of doing this outside of macros?

    Regards, M

  • Alex Skrypnyk 6175 posts 24186 karma points MVP 8x admin c-trib
    Nov 08, 2016 @ 16:49
    Alex Skrypnyk
    0

    Hi M,

    You have to specify type of input parameter, try this one:

    var node = Umbraco.Content((int)CurrentPage.picker);
    

    Thanks,

    Alex

  • Alex Skrypnyk 6175 posts 24186 karma points MVP 8x admin c-trib
    Nov 08, 2016 @ 16:51
    Alex Skrypnyk
    0

    Even better will be like that:

    var node = Umbraco.TypedContent(Umbraco.AssignedContentItem.GetPropertyValue<int>("picker"));
    
    var content = node.GetPropertyValue("content");
    

    Thanks,

    Alex

  • Alex Skrypnyk 6175 posts 24186 karma points MVP 8x admin c-trib
    Nov 08, 2016 @ 17:11
    Alex Skrypnyk
    0

    CurrentPage.picker is html?

    var node = Umbraco.TypedContent(Umbraco.AssignedContentItem.GetPropertyValue<int>("picker"));
    
    if(node != null)
    {
    var content = node.GetPropertyValue("content");
    }
    
  • M T 35 posts 212 karma points
    Nov 09, 2016 @ 10:15
    M T
    100

    Working solution.

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    @using Umbraco.Core.Models
    
    
    @{
       var node = Umbraco.TypedContent(Model.MacroParameters["picker"]);
    
        var content = node.GetPropertyValue("content");
    
        @content;
    
    }
    
  • Alex Skrypnyk 6175 posts 24186 karma points MVP 8x admin c-trib
    Nov 09, 2016 @ 11:38
    Alex Skrypnyk
    0

    Great, glad that you found solution!!!

Please Sign in or register to post replies

Write your reply to:

Draft