Macro is working but keeps getting RESOLVEDATAMACRO errors

Chris Adams asked on December 22, 2017 20:24

Hi,

We are getting tons of MACRORESOLVER error on one of our pages and I was able to pinpoint where it is coming from. We have a macro in a static html web part like the code below and I can't figure out what's wrong. It is working as expected too so I'm confused. Is the syntax wrong?

 <div class="row">
  <div class="col-sm-4 newsltr-two-btn">
  {% if(!String.IsNullOrEmpty(Document)) { %}
  <a target="_blank" href="~/getattachment/{% Document %}/attachment.aspx" download>{% DocumentText %</a>
  {% } else if (!String.IsNullOrEmpty(ExternalDocumentUrl)) { %}
  <a target="_blank" href="{% ExternalDocumentUrl %}">{% DocumentText %}</a>
  {% } #%}  
    </div>      
</div>

Event Log:

Error while evaluating expression: if(!string.IsNullOrEmpty(Document)) { print(ResolveMacros("\r\n {% DocumentText %} \r\n ")) } else if (!string.IsNullOrEmpty(ExternalDocumentUrl)) { print(ResolveMacros("\r\n {% DocumentText %} \r\n ")) } |(user)paulo|(hash)7b864efc818f93934b7bfb4c7d92234dc8c506e841ed30c3b661f8bee604d86b

System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index at System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource) at CMS.MacroEngine.ExpressionEvaluator.EvaluateCondition(Boolean& match, Boolean& securityPassed, DataRow drLogItem, DateTime evaluationStarted)

Recent Answers


Brenden Kehren answered on December 22, 2017 20:38

No need to cross-post on SO as the posts are automatically brought over to the DevNet if they are tagged with "Kentico".

See the answer I provided, looks like a syntax error.

    <div class="row">
      <div class="col-sm-4 newsltr-two-btn">
      {% if(!String.IsNullOrEmpty(Document)) { %}
      <a target="_blank" href="~/getattachment/{% Document %}/attachment.aspx" download>{% DocumentText %</a> // your error is here, missing a closing curly brace after the percent sign for DocumentText
      {% } else if (!String.IsNullOrEmpty(ExternalDocumentUrl)) { %}
      <a target="_blank" href="{% ExternalDocumentUrl %}">{% DocumentText %}</a>
      {% } #%}  
        </div>      
    </div>
2 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.