矩阵块无法使用文本方法

发布于 2025-02-11 04:31:21 字数 1808 浏览 1 评论 0原文

我是制作CM的新手,只是学习基础知识。我一直在关注他们的文档中包含的教程( https://craftcms.com /docs/get-start tutorial/)但是,当我尝试输入模板代码显示矩阵块时,我会得到此错误 -

twig runtime错误 - twig \ error \ runtimeerror

调用未知方法:craft \ elements \ elements \ elements \ elements \ elements \ elements \ elements \ elements \ elements \ elements \ MatrixBlock :: Text()

这是模板的代码-matrix-content“ rel =“ nofollow noreferrer”> https://craftcms.com/docs/getting-started-tutorial/build/build/templates.html#display-matrix-matrix-content

我不明白我不明白我如何在看似基本的函数上可能会直接从教程复制出一个未知的方法错误?

{% extends "_layout.twig" %}

{% set featureImage = {
  mode: 'crop',
  width: 900,
  height: 600,
  quality: 90
} %}

{% block content %}
  <h1 class="text-4xl text-black font-display my-4">{{ entry.title }}</h1>

  <time class="text-sm block pb-4" datetime="{{ entry.postDate | date('Y-m-d') }}">{{ entry.postDate | date('d M Y') }}</time>

  {% if entry.featureImage|length %}
    {% for image in entry.featureImage.all() %}
      <img src="{{ image.getUrl(featureImage) }}" alt="{{ image.title }}" />
    {% endfor %}
  {% endif %}

  <div class="my-8">
    {% for block in entry.postContent.all() %}
      <div class="my-4">
        {% if block.type == 'text' %}
          {{ block.text }}
        {% elseif block.type == 'image' %}
          {% for image in block.image.all() %}
            <img src="{{ image.url }}" alt="{{ image.title }}" />
          {% endfor %}
        {% endif %}
      </div>
    {% endfor %}
  </div>
{% endblock %}```


  [1]: https://craftcms.com/docs/getting-started-tutorial/build/templates.html#display-matrix-content

I am brand new to Craft CMS and just learning the basics. I've been following along with the tutorial included in their docs (https://craftcms.com/docs/getting-started-tutorial/) but when I try to enter the template code to display a matrix block I get this error -

Twig Runtime Error – Twig\Error\RuntimeError

Calling unknown method: craft\elements\MatrixBlock::text()

This is the code for the template which is copied straight from the documentation example here https://craftcms.com/docs/getting-started-tutorial/build/templates.html#display-matrix-content

I don't understand how I could be getting an unknown method error on a seemingly basic function that's copied straight from the tutorial?

{% extends "_layout.twig" %}

{% set featureImage = {
  mode: 'crop',
  width: 900,
  height: 600,
  quality: 90
} %}

{% block content %}
  <h1 class="text-4xl text-black font-display my-4">{{ entry.title }}</h1>

  <time class="text-sm block pb-4" datetime="{{ entry.postDate | date('Y-m-d') }}">{{ entry.postDate | date('d M Y') }}</time>

  {% if entry.featureImage|length %}
    {% for image in entry.featureImage.all() %}
      <img src="{{ image.getUrl(featureImage) }}" alt="{{ image.title }}" />
    {% endfor %}
  {% endif %}

  <div class="my-8">
    {% for block in entry.postContent.all() %}
      <div class="my-4">
        {% if block.type == 'text' %}
          {{ block.text }}
        {% elseif block.type == 'image' %}
          {% for image in block.image.all() %}
            <img src="{{ image.url }}" alt="{{ image.title }}" />
          {% endfor %}
        {% endif %}
      </div>
    {% endfor %}
  </div>
{% endblock %}```


  [1]: https://craftcms.com/docs/getting-started-tutorial/build/templates.html#display-matrix-content

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文