---
title: "get_metafield"

doc_type: static
doc_category: static
doc_version: v20270301
source_url:
  html: 'https://developer.shopline.com/zh-hans-cn/docs/sline/filter/get-metafield'
  md: 'https://developer.shopline.com/zh-hans-cn/docs/sline/filter/get-metafield.md'
---

# get_metafield


    通过 `namespace` 和 `key` 获取指定资源的 [metafield](https://developer.shopline.com/zh-hans-cn/docs/sline/object/metafield.md) object。

    与 [get_metafields](https://developer.shopline.com/zh-hans-cn/docs/sline/filter/get-metafields.md) filter 不同的是，`get_metafield` filter 通过指定 `namespace` 和 `key` 来查询单个 `metafield` object。

> **注意**
>
> 为确保商店的性能和响应速度，在渲染一个页面的过程中，该过滤器的调用次数上限是 50 次。如果多次调用的传入参数一致，则这些调用在计数时会被视为一次。调用次数达到上限后，后续调用将会返回 `nil`。



    
`object | get_metafield(namespace, key)` 返回一个 [`metafield`](https://developer.shopline.com/zh-hans-cn/docs/sline/object/metafield.md) 对象。
    



    
        ## 必选参数

        
            - `object` `any`: 指定的资源对象。适用范围：[product](https://developer.shopline.com/zh-hans-cn/docs/sline/object/product.md)
、[collection](https://developer.shopline.com/zh-hans-cn/docs/sline/object/collection.md)
、[blog](https://developer.shopline.com/zh-hans-cn/docs/sline/object/blog.md)
、[article](https://developer.shopline.com/zh-hans-cn/docs/sline/object/article.md)
、[page](https://developer.shopline.com/zh-hans-cn/docs/sline/object/page.md)
、[order](https://developer.shopline.com/zh-hans-cn/docs/sline/object/order.md)
、[customer](https://developer.shopline.com/zh-hans-cn/docs/sline/object/customer.md)
、[variant](https://developer.shopline.com/zh-hans-cn/docs/sline/object/variant.md)
、[shop](https://developer.shopline.com/zh-hans-cn/docs/sline/object/shop.md)
、[company](https://developer.shopline.com/zh-hans-cn/docs/sline/object/company.md)。
        
            - `namespace` `string`: 元字段的命名空间。
        
            - `key` `string`: 元字段在其命名空间下的唯一标识符。
        
    





    
        ## 例子

        
            

            


            

            
<SlineExample path={'/products/vip3'} objects={ 
    [""] 
}>
```sline
{{#var mf = product | get_metafield("demo_ns", "demo_key") /}}
{{ mf.value }}
```
</SlineExample>
            
        
    
