在页面静态文本显示文档名称中声明变量

Declaring variable in static text display document name on page

我在静态文本 Web 部件文本字段中声明变量时遇到问题。当我使用这样的代码时:

{% doc = Documents.WithAllData[CurrentDocument.Children["Hero"].Children[0].GetValue("NodeAliasPath")]; #%}

<p>
  {% if (!string.IsNullOrEmpty(doc.HeroButtonLabel)) { %}
  <a class="btn btn-secondary arrow" href="{% doc.HeroUrl #%}">
    {% doc.HeroButtonLabel #%}
  </a>
  {% } #%}
  {% if (!string.IsNullOrEmpty(doc.HeroUrl2Label)) { %}
  <a class="btn btn-secondary arrow" href="{% doc.HeroUrl2 #%}">
    {% doc.HeroUrl2Label #%}
  </a>
  {% } #%}
</p>

第一行在呈现的页面上显示文档名称(其余代码工作正常)。我用 Kentico 10.

添加 return 语句,使您的行内容如下:

{% 
  doc = Documents.WithAllData[CurrentDocument.Children["Hero"].Children[0].GetValue("NodeAliasPath")];
  return;
#%}