Return to Snippet

Revision: 35587
at November 10, 2010 14:56 by Elijah


Updated Code
public string RenderMacro(string input, int nodeId) {
    if (string.IsNullOrEmpty(input))
        return string.Empty;
    var regex = new Regex("<\\?UMBRACO_MACRO[^>]*/>", RegexOptions.Multiline | RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);
    return regex.Replace(input, p => {
        try {
            return umbraco.library.RenderMacroContent(p.Value, nodeId);
        } catch (Exception ex) {
            Trace.Warn(ex.Message);
            return "Problems Rendering Macro";
        }
    });
}

Revision: 35586
at November 10, 2010 14:55 by Elijah


Updated Code
public string ParseContent(string input, int nodeId) {
    if (string.IsNullOrEmpty(input))
        return string.Empty;
    var regex = new Regex("<\\?UMBRACO_MACRO[^>]*/>", RegexOptions.Multiline | RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);
    return regex.Replace(input, p => {
        try {
            return umbraco.library.RenderMacroContent(p.Value, nodeId);
        } catch (Exception ex) {
            Trace.Warn(ex.Message);
            return "Problems Rendering Macro";
        }
    });
}

Revision: 35585
at November 10, 2010 14:55 by Elijah


Updated Code
public string ParseContent(string input, int nodeId) {
            if (string.IsNullOrEmpty(input))
                return string.Empty;
            var regex = new Regex("<\\?UMBRACO_MACRO[^>]*/>", RegexOptions.Multiline | RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);
            return regex.Replace(input, p => {
                try {
                    return umbraco.library.RenderMacroContent(p.Value, nodeId);
                } catch (Exception ex) {
                    Trace.Warn(ex.Message);
                    return "Problems Rendering Macro";
                }
            });
}

Revision: 35584
at November 10, 2010 14:54 by Elijah


Initial Code
public string ParseContent(string input, int nodeId) {
            if (string.IsNullOrEmpty(input))
                return string.Empty;
            var regex = new Regex("<\\?UMBRACO_MACRO[^>]*/>", RegexOptions.Multiline | RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);
            return regex.Replace(input, p => {
                try {
                    return umbraco.library.RenderMacroContent(p.Value, nodeId);
                } catch (Exception ex) {
                    Trace.Warn(ex.Message);
                    return "Problems Rendering Macro";
                }
            });
        }

Initial URL


Initial Description


Initial Title
Umbraco Render Macro Inside A String

Initial Tags


Initial Language
C#