you could use umbraco.library.RenderMacroContent() if that macro references a xslt file. If that macro references a user control, it won't work. Alternatively, could move the logic for IsCurrentOwner() into the macro
Yeah I wanted to leave the logic for IsCurrentOwner seperate, though, as it's more extensible this way - it means I can easily make any body of content only visible to the owner rather than changing / creating a lot more controls.
/// <summary> /// Renders the user control. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="controlPath">The control path.</param> /// <param name="initControlAction">The init control action.</param> /// <param name="context">The context.</param> /// <returns> /// The rendered control output /// </returns> public static string RenderControl<T>(string controlPath, Action<T> initControlAction, HttpContextWrapper context = null) where T : UserControl { var pageHolder = new Page(); var control = (T)pageHolder.LoadControl(controlPath);
/// <summary> /// Renders the control. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="initControlAction">The init control action.</param> /// <param name="context">The context.</param> /// <returns> /// The rendered control output /// </returns> public static string RenderControl<T>(Action<T> initControlAction, HttpContextWrapper context = null) where T : Control { var pageHolder = new Page(); var control = pageHolder.LoadControl(typeof(T), null);
Razor and Macro's
Hi, it appears as they I cannot use a Macro from within a Razor macro? The result I get when trying to do something like this:
<umbraco:Macro language="cshtml" runat="server">
@if (Model.IsCurrentOwner()) {
<div>Some text</div>
<umbraco:Macro Prop1="X" alias="MyMacro" runat="server" />
}
</umbraco:Macro>
Is the error: The 'Text' property of 'umbraco:Macro' does not allow child objects
Is there any way I can achieve the above?
Cheers
John,
you could use umbraco.library.RenderMacroContent() if that macro references a xslt file. If that macro references a user control, it won't work. Alternatively, could move the logic for IsCurrentOwner() into the macro
Hope this helps.
Regards,
/Dirk
Yeah I wanted to leave the logic for IsCurrentOwner seperate, though, as it's more extensible this way - it means I can easily make any body of content only visible to the owner rather than changing / creating a lot more controls.
What I've ended up doing is creating a RenderControl method using the Server.Execute method mentioned here: http://www.jonkragh.com/index.php/rendering-an-asp-net-usercontrol-to-a-string/comment-page-1/ meaning I can do this:
Could u post u UIHelper.RenderControl method ?
Sure thing, there's actually 3 methods:
is working on a reply...