矩阵块无法使用文本方法
我是制作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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论