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 127 karma points
    Aug 19, 2019 @ 16:06

    How to get macro content in UmbracoApiController v8


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


    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 127 karma points
    Aug 27, 2019 @ 13:02

    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");
  • Michele Di Maria 34 posts 239 karma points
    Mar 04, 2021 @ 19:52
    Michele Di Maria

    Thanks, this saved my day!!

Please Sign in or register to post replies

Write your reply to: