x First time here? Check out the FAQ
  • Avatar98posts146karma

    Rendering RTE with embedded macros in Razor

    Fengelz started this topic 11 months ago , this topic was edited at: Tuesday, February 07, 2012 8:47 PM, Go directly to the topic solution

    Anybody has any take on how to render richtext properties with embedded macros?

    When I use @Model.bodyText it just gives me the embedded macro code (which makes good sense i suppose).

    I could of course make a custom functionality that searches for embedded macros, but was wondering if umbraco already had this sort of functionality?

    best regards 

    - Sune


  • Replies

  • Fengelz posted this reply 11 months ago

    Ok to answer my own question: @Html.Raw(umbraco.library.RenderMacroContent(Model.bodyText, Model.Id)) seemd to do the trick.

     


  • Avatar248posts469karma
    Comment with ID: 88601
    Murray Roke posted this reply 8 months ago

    Thanks Fengelz, I found I had to do this:

    @Html.Raw(umbraco.library.RenderMacroContent(Model.secondaryBodyText.ToString(), Model.Id))

  • Avatar98posts146karma
    Comment with ID: 89687
    Fengelz posted this reply 8 months ago

    Yeah. 

    Usually a good idea to stringify properties in razor. You never know what you'll be getting... :)


  • Sam Moore posted this reply 3 months ago

    so I need some help with this. I can get the helper to render something, but it's not rendering the media item's umbracoFile property :-\... this macro works everywhere else on the site except through this helper call. It appears as if my macro params are not being populated correctly. Any Idea what is causing this?

    @umbraco.library.RenderMacroContent(node.BodyText.ToString(), (int)node.Id)

     

    The macro is configured like this:

      <?UMBRACO_MACRO showcaption="1" mediaitem="65663"
    largeitem="65382" macroAlias="InsertImageItem"
    enlargeimage="1" /> 

     

    The macro looks like this in the code-behind of the ascx:

    public partial class WRO_InsertImage : System.Web.UI.UserControl
        {
            public int mediaItem { get; set; }
    		// snip other params
    
            protected void Page_Load(object sender, EventArgs e)
            {
                // try to get media item
                Media m = new Media(mediaItem);
                if (m == null)
                    return;
    				
    			// snip the rest for clarity
            }
        }
    

Please login or Sign up To post replies