Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Simon Smith 19 posts 41 karma points
    Jan 20, 2012 @ 13:46
    Simon Smith
    0

    Macros in content not being parsed

    I have the following Razor script within a template on Umbraco 4.7:

        @{
          if (Model.Qfacts.Count() > 0) {
            <div class="editable-content article-information-content narrow">
              @Html.Raw(@Model.BodyText.ToString())
            </div>
            <div class="qfacts">
            <div class="top">
              <ul>
                @{
                  int totalFacts = Model.Qfacts.Count();
                  int currentFact = 0;
                }
                @foreach (var fact in Model.Qfacts) {
                  <li><div>@fact.BodyText</div>
                  @if (++currentFact != totalFacts) {
                    <hr/>
                  }
                </li>
                }
              </ul>
              </div>
              <div class="bottom"></div>
            </div>
          } else {
            <div class="editable-content article-information-content">
              @Model.BodyText
            </div>
          }
        }

    This works fine with basic content, however when I insert a macro through the editor (which is an ascx control) the output of @Model.BodyText isn't being parsed to replace the placeholder element:

    <?UMBRACO_MACRO imageurl="1088"
    macroAlias="ContentImageZoom" zoomimageurl="1097" /> 

    How can I change the Razor script to ouptut the content with the macro correctly inserted? The answer is probably staring me in the face, but it is Friday!

    Thanks,
    Simon

  • Sebastiaan Janssen 4899 posts 14655 karma points MVP admin hq
    Jan 20, 2012 @ 13:54
    Sebastiaan Janssen
    0

    Have a look at this topic, the solution is probably:

     

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

     

     

  • Simon Smith 19 posts 41 karma points
    Jan 20, 2012 @ 13:57
    Simon Smith
    0

    That's it! Thanks Sebastiaan :)

  • Rodion Novoselov 694 posts 859 karma points
    Jan 20, 2012 @ 13:59
    Rodion Novoselov
    0

    Hi. There was a thread just recently where the similar stuff about an XSLT macro was talked over:

    http://our.umbraco.org/forum/developers/xslt/27770-Caching-output-of-umbracolibraryItem-in-XSLT-macro

    I have no clue however how much it's relevant to razor macros.

  • 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.

Please Sign in or register to post replies