I’m ---

Do IF tokens not work on Product Detail templates?

I tried using ##IF_PRODUCT_[My Product ID]## in the Product Detail template and the token text was just echo'd to the browser as if it were text/html.

Are we not supposed to use these within this template?

I am trying to use an image as a product teaser and not all products currently have an image, hence the need for the IF token.

Just wondering if this is an intended result or a bug.
1 person has
this question
+1
Reply
  • @Michael are you adding this into the description field, or inside the template itself?

    If its inside the template, you can't specify an exact product ID or else it will only work for that product specifically.

    What you want to try is something like this:

    ##IF_PRODUCT_10##
    TEASER
    ##ELSE## ##IF_PRODUCT_11##
    TEASER
    ##ELSE## ##IF_PRODUCT_12##
    //NOTHING
    ##END_IF##
    ##END_IF##
    ##END_IF##

    So you will have to specify as above, each product ID that requires this image in the fashion above.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. kidding, amused, unsure, silly indifferent, undecided, unconcerned sad, anxious, confused, frustrated happy, confident, thankful, excited

  • That's pretty close to what I did, my exact markup was:

    ##IF_PRODUCT_27_30##

    My html to display image

    ##END_IF##

    And this is in the template itself, to display above product price, sku, etc.

    BTW - The teaser image shows fine, I just want to limit this to these two images while the client decides how they want to proceed, otherwise all the products that don't have teaser images show a missing image.

    As a test I tried writing it more similar to your syntax:

    ##IF_PRODUCT##

    ##ELSE## ##IF_PRODUCT_27##
    <img src="[Image_Path]<?php print $product->getId()?>teaser.png" style="border:0;" />
    ##ELSE## ##IF_PRODUCT_30##
    <img src="[Image_Path]<?php print $product->getId()?>teaser.png" style="border:0;" />
    ##END_IF##
    ##END_IF##
    ##END_IF##

    And here's a screenshot of the result:

  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. kidding, amused, unsure, silly indifferent, undecided, unconcerned sad, anxious, confused, frustrated happy, confident, thankful, excited

  • Michael,

    When viewing the template file for your product details page in your store admin you should see a link in the top left corner that will show you a list of tokens that can be used. In this case I do not believe that the ##IF_PRODUCT## is one of the available options. To get around this however, you should be able to add the if statements that you are wanting somewhere in the header file. Because each product has a unique id, the if statements should still catch the products that you are wanting to catch even if they are in the header and not the product-details template.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. kidding, amused, unsure, silly indifferent, undecided, unconcerned sad, anxious, confused, frustrated happy, confident, thankful, excited

  • I’m happy
    Thanks for the idea Brad. I'll give that a try next time I am trying to do something similar. We ended up just getting the complete set of images done and in place ASAP.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. kidding, amused, unsure, silly indifferent, undecided, unconcerned sad, anxious, confused, frustrated happy, confident, thankful, excited