Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

230
Visualizações
Luquid check if metafield exists

I want to check if a metafield (created with metafields Guru) exists on a product or not and based on that change a variable to show or hide the div holding the metafield.

I got this:

{% assign display = "inline-block" %}

{% if product.metafields.energielabel.energie.value  == blank %}
{% assign display = "none" %}
{% endif %}

<div id="energielabel-container"><img class="label" src="https://cdn.shopify.com/s/files/1/0619/8034/4516/{{ product.metafields.energielabel.energie.value }}" /></div>


<style>
#energielabel-container {
width: 80px;
display: {{ display }};
}


</style>

When I just add some example letters into to the if condition it´s working as it should (empty metafield = shows the exaple letters ), but redefining the variable doesn´t work...

about 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

<img class="label" src="https://cdn.shopify.com/s/files/1/0619/8034/4516/{{product.metafields.energielabel.energie.value}}" />

The line above is questionable. you should store the whole url instead;

using your method will create extra code and errors; the img tag will still fetch the url that does not exist. So just check with if tag and put all code inside.

{% if product.metafields.energielabel.energie.value %}

<style>
#energielabel-container {
width: 80px;
display: inline-block;
}
</style>

<div id="energielabel-container">
    <img class="label" src="https://cdn.shopify.com/s/files/1/0619/8034/4516/{{product.metafields.energielabel.energie.value}}" />
</div>


{% endif %}
about 4 years ago · Santiago Trujillo Relatório

0

Your if statement checks if metafield is blank using == operator. What you want is to check if it's not blank (if it exists)

Try:

{% if product.metafields.energielabel.energie.value != blank %}
  {% assign display = "none" %}
{% endif %}
about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda