Copied to clipboard

Flag this post as spam?

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


  • progproger 49 posts 106 karma points
    Aug 19, 2019 @ 16:06
    progproger
    0

    How to get macro content in UmbracoApiController v8

    Hi,

    I'm trying to get macro content in one of the api methods using:

    Current.UmbracoHelper.RenderMacro("macroalias");

    but getting an error:

    Cannot return the IPublishedContent because the UmbracoHelper was not constructed with an IPublishedContent.

    Can someone please point me the correct way?

  • progproger 49 posts 106 karma points
    28 days ago
    progproger
    0

    For those who has the same issue or will ever have...

    Not sure if it's the best way, but i've created new instance of UmbracoHelper and that helped:

    UmbracoHelper helper = new UmbracoHelper(umbPage, Umbraco.TagQuery, _dicFactory, _compRenderer, Umbraco.ContentQuery, Current.UmbracoHelper.MembershipHelper);
    

    where _dicFactory and _compRenderer are injected to existing api controller...

    public UmbracoContentApiController(ICultureDictionaryFactory dicFactory, IUmbracoComponentRenderer compRenderer)
            {
                _dicFactory = dicFactory;
                _compRenderer = compRenderer;
            }
    

    Then you can easily render macro using:

    var macro = helper.RenderMacro("MacroAlias");
    
Please Sign in or register to post replies

Write your reply to:

Draft