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>
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().
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 :)
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" />
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:)
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));
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);
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
But when I visit the page I only see :
I saw for some folks using XSLT for their macros they change the RTE output to be :
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 ?
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
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.
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
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:)
Hmm, I'm all out of ideas then - but please share the solution with us once you find it :-)
/Jan
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:
HTH,
Hendy
is working on a reply...
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.