Posted By

Elijah on 11/10/10


Tagged

umbraco


Versions (?)

Umbraco Render Macro Inside A String


 / Published in: C#
 

  1. public string RenderMacro(string input, int nodeId) {
  2. if (string.IsNullOrEmpty(input))
  3. return string.Empty;
  4. var regex = new Regex("<\\?UMBRACO_MACRO[^>]*/>", RegexOptions.Multiline | RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);
  5. return regex.Replace(input, p => {
  6. try {
  7. return umbraco.library.RenderMacroContent(p.Value, nodeId);
  8. } catch (Exception ex) {
  9. Trace.Warn(ex.Message);
  10. return "Problems Rendering Macro";
  11. }
  12. });
  13. }

Report this snippet  

You need to login to post a comment.