Recommendations > template > Custom field — Nosto Community

Recommendations > template > Custom field

DistriartisanDistriartisan Posts: 35Member

I'd like to use custom fields
Something like : if custom field value is not empty, dsiplay custom field value
I tried with $!sku.getCustomField(delai_livraison)
It doesn't work 

Can you please help me 



  • KonstantinKonstantin Posts: 26Walking Wisdom admin
    Thanks for opening a separate topic for this one.

    Here is what I have from a case I worked on:
    ISSUE: how to call custom fields info
    CODE: $!product.getCustomField('color') 

    ISSUE: how to leverage custom fields info as a condition
    CODE: #if($!product.getCustomField(“color").toString().contains(“blue"))

    Can you give this a try and see if it works for you?
  • DistriartisanDistriartisan Posts: 35Member

    Thanks a lot
  • JacopoJacopo Posts: 47Walking Wisdom, Coding Expert admin
    Hello @Distriartisan

    Konstantin's code is verbose and uselessly long, taking a time (we do not necessarily have to) of the templating language in our templates (sorry the repetition of "template" eheh).
    Also, it will fail in the case the custom field is not "blue" but, for example, "red" - in that case nothing will be printed, altho the field is populated.

    In the language we use in templates, Apache Velocity, the "!" (question mark) is the boolean operator "not" (called "bang" in technical slang).

    The statement:


    contains in it all you need. Thanks to that "!" placed there, it will go like this: if the "color" field is populate, it will return the color, otherwise will return "false" (as if the custom field is not populated) and that won't be printed.



    Try this out and let us know!

  • DistriartisanDistriartisan Posts: 35Member
    It's live 

    Thanks a lot !

Sign In or Register to comment.

Read our Terms&Conditions before commenting and posting