Copied to clipboard

Flag this post as spam?

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


  • Grant Davies 3 posts 23 karma points
    Aug 16, 2012 @ 17:24
    Grant Davies
    0

    Macro use in rich text editor

    Hi,

    we have a specific video player we use in our site where the video is "predetermined", but one some generic pages I want to use the same video control.

    We have a videoLightBoxControl.ascx that can output the appropriate markup and javascript for the player and I've added some parameters to it for the video URL

    When I embed this macro via the rich content editor I see the following added in "html" view

    div umb_contentitemid="http://www.youtube.com/embed/uoF5TnWxqNI" umb_macroalias="VideoLightBox" umb_videotitletext="" umb_videosrc="" ismacro="true" onresizestart="return false;" umbversionid="d332d2af-f460-4164-be18-eac811907e3a" umbpageid="1213" title="This is rendered content from macro" class="umbMacroHolder"><!-- startUmbMacro --><span style="color: green;"><strong>VideoLightBox</strong><br />No macro content available for WYSIWYG editing</span><!-- endUmbMacro --></div>

     

    But when I visit the page I only see :

    <?UMBRACO_MACRO videosrc="" videotitletext=""
     contentitemid="http://www.youtube.com/embed/uoF5TnWxqNI"
     macroAlias="VideoLightBox" />

     

    I saw for some folks using XSLT for their macros they change the RTE output to be :

    <xsl:value-of select="$currentPage/data [@alias='pageContent']" disable-output-escaping="yes" />

    Since I'm not using XSLT for my macros the code that outputs the results of the page is :

    umbracoItem.GetProperty("content");
    

    Where umbracoItem is a umbraco.NodeFactory.Node;  This gets the content of the rich text field named "content" which all our pages are based on.

     

    Do we need to do something different to get the content with the macro rendered into it ?

     

     

  • Jan Skovgaard 11258 posts 23500 karma points MVP 7x admin c-trib
    Aug 16, 2012 @ 21:25
    Jan Skovgaard
    0

    Hi Grant and welcome to our :)

    What version of Umbraco are you using?

    I must admit that c# is not my best skill, but as far as I know it should be possible to use the umbraco.library extensions in C# as well, so even thought the example here http://our.umbraco.org/wiki/reference/umbracolibrary/getitem is based on XSLT you should be able to use umbraco.library:GetItem().

    Hope this helps.

    /Jan

  • Grant Davies 3 posts 23 karma points
    Aug 17, 2012 @ 00:16
    Grant Davies
    0

    Thanks Jan, and for the welcome :) we've been using umbraco for a while but since we use sitecore too its been pretty easy so far, until I needed to find a way for users to embed video easily within a content page :)  

    We are using umbraco 4.7.1.1

    I tried modifying my getItem code to :

    content = (umbracoItem.GetProperty("content");

    content = umbraco.library.RenderMacroContent(content, umbracoItem.Id);

    hoping that method would expand the macro, but didn't seem to work, but checking I did it correctly :)

     

    Grant.

     

  • Jan Skovgaard 11258 posts 23500 karma points MVP 7x admin c-trib
    Aug 17, 2012 @ 06:50
    Jan Skovgaard
    0

    Hi Grant

    Hmm, would it be possible for you to simply just use the umbraco:item on the masterpage to render the macro content? You should be able to have the content rendered by placing this in the template (Masterpage): <umbraco:Item field="content" runat="server" />

    Hope this helps.

    /Jan

  • Grant Davies 3 posts 23 karma points
    Aug 17, 2012 @ 17:58
    Grant Davies
    0

    That doesn't render the macro, the code seems to be working now, its just not getting any parameters I set on the macro, but at least its being output so closer:)

  • Jan Skovgaard 11258 posts 23500 karma points MVP 7x admin c-trib
    Aug 17, 2012 @ 18:14
    Jan Skovgaard
    0

    Hmm, I'm all out of ideas then - but please share the solution with us once you find it :-)

    /Jan

  • Hendy Racher 861 posts 3844 karma points MVP 2x admin c-trib
    Aug 20, 2012 @ 10:54
    Hendy Racher
    0

    Hi Grant,

    The <umbraco:Item ... /> server control that Jan mentioned above should parse the macro tokens and render their output, but if you need to parse them yourself the following snippet might be useful:

    using System.Text.RegularExpressions;
    using System.Web.UI;
    using System.Web.Text;
    using System.IO;
    using System.Xml;
    using umbraco.presentation.templateControls;

    namespace ExtensionMethods
    {
    /// <summary>
    /// Parse a text string for any UMBRACO_MACRO tokens, and replace them with their rendered macros
    /// </summary>
    public static string ProcessUmbracoMacros(this string text)
    {
    bool macroFound;
    do
    {
    Match macroMatch = Regex.Match(text, @"<\?UMBRACO_MACRO .*macroAlias="".*"".*/>", RegexOptions.Singleline);
    macroFound = macroMatch.Success;

    if (macroFound)
    {
    XmlDocument xmlDocument = new XmlDocument();

    // remove the '?' char from the token so that can be treated as xml
    xmlDocument.LoadXml(macroMatch.Value.Remove(1, 1));

    XmlNode macroXmlNode = xmlDocument.SelectSingleNode("//UMBRACO_MACRO");

    Macro macro = new Macro();
    macro.Alias = macroXmlNode.Attributes["macroAlias"].Value;

    foreach (XmlAttribute attribute in macroXmlNode.Attributes)
    {
    if (attribute.Name != "macroAlias")
    {
    macro.MacroAttributes.Add(attribute.Name, attribute.Value);
    }
    }

    text = text.Remove(macroMatch.Index, macroMatch.Length);
    text = text.Insert(macroMatch.Index, macro.RenderToString());
    }
    }
    while (macroFound);

    return text;
    }

    /// <summary>
    /// Renders an ASP.NET control into a string
    /// </summary>
    public static string RenderToString(this Control control)
    {
    StringBuilder stringBuilder = new StringBuilder();
    StringWriter stringWriter = new StringWriter(stringBuilder);
    HtmlTextWriter htmlTextWriter = new HtmlTextWriter(stringWriter);

    control.RenderControl(htmlTextWriter);

    return htmlTextWriter.InnerWriter.ToString();
    }
    }

    HTH,

    Hendy

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies