Copied to clipboard

Flag this post as spam?

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


  • Carl Lundblad 12 posts 33 karma points
    Mar 18, 2013 @ 14:30
    Carl Lundblad
    0

    RTE-content through ajax, rendering macro content

    Hi, 

    I trierd searching the forum but couldn't find anyting that helped me, so here goes: 

    I'm developing a page on which some content is loaded on demand, with an AJAX-call to a simple webservice that takes a node-ID as a parameter, and returns the content of a Richtext-Editor-property on that node. This works very well, as long as I dont have any macros included in the RTE, which still outputs all the html-content but with the macro only as a comment(<!--?UMBRACO_MACRO .... /-->).

    Is there any simple way of making umbraco return the content of the RTE with all macros rendered?

    I tried this: http://our.umbraco.org/forum/developers/api-questions/26364-Macro-content-not-showing-up-Need-workaround (using library.RenderMacroContent) but couldn't quite get it to run, and then I read that it only works well for XSLT-macros, while my macros all are .NET-usercontrols.

     

    I'm running umbraco 6.0.0

    Thanks

  • Andreas Iseli 150 posts 427 karma points
    Mar 20, 2013 @ 16:44
    Andreas Iseli
    0

    I'm using a FieldRenderer class as an adaption of umbracos internal classes to achieve what you are looking for. You should easy be able to integrate my code snippet into your webservice. Have a look at it:

    http://our.umbraco.org/forum/developers/razor/39335-Rendering-macro-contents-with-razor

  • Carl Lundblad 12 posts 33 karma points
    Mar 22, 2013 @ 12:15
    Carl Lundblad
    0

    Hello again,

    Thanks for your answer, Andreas. I did try it out but I couldn't get it to render macros based on .NET-usercontrols. (Perhaps some viewstate-issues?). So what I ended up doing was creating a template for my content node(inheriting straight from the default.master to not have any reduntant html), and included the fields I needed to fetch wrapped in the html I needed to present my data in the page calling the webservice. Then I rewrote my webservice to fetch the content of that node through it's url. Success! :)

    Code in the webservice, in case someone is interested:

                var url = string.Format("{0}://{1}{2}", HttpContext.Current.Request.Url.Scheme, HttpContext.Current.Request.Url.Host, node.NiceUrl);
                var result = string.Empty;
                var r = HttpWebRequest.Create(url);
                using (var response = r.GetResponse() as HttpWebResponse)
                {
                    var reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
                    result = reader.ReadToEnd();
                }
               
                return result;

    /Carl

Please Sign in or register to post replies

Write your reply to:

Draft