英文:
How Do I Get MetaObject Values On Single MetaObject Page In Shopify
问题
我正在使用Shopify中的metaObjects。我已创建了一个名为“Projects”的metaObject。我创建了一个名为“Projects”的页面,通过Liquid代码显示了这些保存的项目。它按照“Projects”页面的要求工作,但现在我想在单独的页面上显示每个项目的详细信息。我应该如何处理?比如,我应该创建一个页面并在其中设置一个模板,在该模板中获取metaObject的句柄以显示其详细信息。我遇到了一个问题,就是如何调用同一个单独的页面来显示所有项目的详细信息并显示其详细信息。请问有人能指导一下如何在单个项目页面上获取每个metaObject的值。谢谢。
英文:
I am using metaObjects in shopify. I have created a metaObject name "Projects" . I created a page "Projects" to display those saved projects through liquid code. It is working as per the requirement on Projects page but now i want to display each project detail on single page. How do i approach this ? Like should i create a page and set a template on it and in that template , fetch the metaobject handle to display its details . I am facing issue like how do i call the same single page for all projects details and display its details. Can someone please guide what is the possible way to get each metaObject values on single project page .
Thanks
答案1
得分: 3
在Shopify管理后台创建了元对象定义之后,接下来需要在项目页面上创建另一个定义,字段类型为"metaobject"。我为了实现这个目标,对产品进行了以下操作:
- 创建了一个"benefit"的元对象,并添加了一个单一文本字段。
- 为产品创建了一个"metafield",其名称为"mixed reference list",并引用了我创建的"benefits"元对象。
- 在产品管理中,通过新的"metafield"添加了一些"benefits"。
- 添加了Liquid代码,以显示附加到页面的"benefits"列表:
<ul>
{% for item in product.metafields.custom.benefits.value -%}
<li>{{ item.benefits }}</li>
{%- endfor %}
</ul>
希望这对您有所帮助!
英文:
After you have created your meta object definition in the Shopify admin you need to then create another definition on your project page with the field type of metaobject I did the following for products to accomplish this :
-
Created meta-object of benefit and added a single text field.
-
Created a metafield for product which was called a mixed reference list and referenced the benefits meta object i created.
-
Added a couple of benefits with the new meta field in the product admin.
-
Added liquid to display the list of benefits attached to the page :
<ul>
{% for item in product.metafields.custom.benefits.value -%}
<li> {{ item.benefits }}</li>
{%- endfor %}
</ul>
I hope this helps!
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论