Author - Ashley Schroder

Hi! I'm Ashley Schroder, the head software engineer at World Wide Access, a company that exports New Zealand products to the world.

I'm an active member of the Magento community, contributing open source extensions to Magento Connect and sharing my Magento experiences through my blog, You can find helpful tips and advice there on a wide range of Magento development issues.

More Info » Follow me on Twitter »

Reader Comments (58)

  1. Tim Durham
    August 4, 2010 at 2:21 pm /

    You have provide details for EXACTLY what I need to accomplish. Only I have been unsuccessful. I am hoping you can provide some insight as to what I am doing wrong.

    This is the code I inserted in the:

    getAttributeText(‘sizing_chart’) == “landau_women_alpha”): ?>
    ?php echo $this->getLayout()->createBlock(‘cms/block’)->setBlockId(‘landau_women_alpha’)->toHtml() ?>

    I create a block called ( landau_women_alpha ). I inserted an HTML sizing chart in that block. it is set to active.

    I have the attribute ( sizing_chart ) which is a drop down menu. I have various values in the drop down. ( landau_sizing_alpha ) is one of the values.

    The test product is the LAN8219. I set the attribute ( sizing_chart ) titled SizingChart, to the drop down selection of landau_sizing_alpha. I only selected the sizing_chart attribute for the Configurable product that is being displayed and not the “simple products” that make up the Configurable product.

    We have many brands, and for every brand we want to display the Sizing Chart that is indicated in the “sizing_chart” attribute. Once I get this working, I would need the PHP IF statements for every possible attribute value so that it will display the correct Sizing Chart for all products. Is it ok to have multiple “IF” statements? I know nothing about PHP.

    Tim D.

  2. Tim Durham
    August 4, 2010 at 2:23 pm /

    It cut off my code snippet πŸ™ . Will try it again.

    getAttributeText('sizing_chart') == "landau_women_alpha"): ?>
    ?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('landau_women_alpha') ->toHtml() ?>

  3. Robert
    August 4, 2010 at 3:36 pm /


    You should simply be able to pull the sizing chart CMS block ID out of your attribute and use it in the createBlock statement without any IF statements like so:

    $sizing_chart_id = getAttributeText('sizing_chart');
    if ($sizing_chart_id) : ?>
    < ?php echo $this->getLayout()->createBlock('cms/block')->setBlockId($sizing_chart_id) ->toHtml() ?>
    < ?php endif; ?>

    The if here is to make sure that you only try to create and display the sizing chart if the attribute is set. You just need to make sure that your sizing_chart attribute values correspond to the CMS Static Block IDs exactly.

  4. Ashley Schroder
    August 4, 2010 at 3:43 pm /

    Hi, Tim – also if it’s not working like you expect, try just echoing out the actual value being returned by getAttributeText() something like this (you don’t have to put it in html comments):
    <!– –>

    Then look at the HTML source to check what valu is actually being fetched – maybe it’s not what you expect.

  5. Ashley Schroder
    August 4, 2010 at 3:45 pm /

    Woops – it nuked my PHP – it’s just an echo of the getAttribute()

  6. Tim
    August 5, 2010 at 1:27 am /

    Robert or Ashley, thanks for the replies. It is still not working for me. Can you tell if I have anything wrong here? (I inserted a space in the < ?php so it would leave all my code)

    getLayout()->createBlock(‘cms/block’)->setBlockId($landau_women_alpha) ->toHtml() ?>

    The “landau_women_alpha” is for sure the value in the sizing_chart attribute that is selected for the configurable product LAN8219. The block id is also saved as landau_women_alpha .

    I have only been working with Magento for 2 months and still learning :0 It seems there should be another file that I have to edit so that when it pulls the block (landau_women_alpha) in, it knows where to place it. Right now, I have put nothing anywhere that would indicate where the block should go.

    I have placed the code I showed you above, at the top of the view.phtml file. I don’t know PHP but I don’t see how the code above is going to properly place the sizing chart (block) at the bottom of the Product Page.

    I would be more than willing to pay one of you to fix this for me then I could see how it was done for other items I may want to dynamically include.


  7. Tim
    August 5, 2010 at 1:38 am /
  8. Tim
    August 5, 2010 at 3:11 am /

    DISREGARD the previous email. It IS WORKING!! πŸ™‚ I am using the original code format from Ashley. Robert when I tried your code I kept getting a fatal error. So I will just use the original code.

    It really helps when you publish up the page after making changes :0 . Actually I was publishing thru Dreamweaver it was not pushing it up for some odd reason.

    So now I have just a couple of other questions.
    1) Since I have about 15-20 different sizing charts among all of our products, do I need to create a complete IF , ENDIF section for each possibility, or can I just have one IF, and one ENDIF, with all the possibilites in the middle (a complete php line for each option). I hope that makes sense.

    2) Would it be just as easy to do this instead. Right close to where they choose their size, have a small image (ruler image with “Sizing Chart” on it) so that when they click that it brings up a popup window to show the sizing chart instead of having it displayed at the bottom of the page. I am really not 100% sure this would even be better. I would just have to get feedback from a customer to see what they liked better.

    Thanks again for all of your help.


    1. Robert
      August 5, 2010 at 8:44 am /

      Hey Tim,

      Answer to 1)
      I strongly suggest to use the code I showed here since it will work and is the best solution in terms of flexibility so you don’t have to add or change your if statements whenever you add or change your block id’s. My code probably doesn’t work because I have added spaces to break the lines so you will need to take them out. So here we go with code without spaces (also take out the space in the < ?php):

      < ?php $sizing_chart_id = getAttributeText('sizing_chart'); if ($sizing_chart_id) : ?>
      < ?php echo $this->getLayout()->createBlock('cms/block')->setBlockId($sizing_chart_id)->toHtml() ?>
      < ?php endif; ?>

      Answer 2)
      From a user perspective, this is a good approach since you are providing an answer to their possible question (how do I know which size to choose?) at the point where they need to make the decision. This is what we’ve done on this page: – note the sizing guide button.

      However, to implement this you will need to do a bit more than the snippet of code provided here.

  9. Stewart Goodwin
    August 18, 2010 at 9:20 am /

    Robert, your example you provided is beautiful. I am looking for a similar implementation of a sizing chart. Do you have any direction you can provide for the following:

    1 – What is the best js or code to use for the tooltip window that does not conflict with other magento js?

    2 – How did you get your button to be next to your attribute? Is there an extension you’re using to visualize your attributes and allow you to insert the size button adjacent to it?

    I’d love to get the same functionality and would pay for it.

    1. Robert
      August 18, 2010 at 10:23 am /

      Hi Stewart,

      thanks for the compliment.

      1 – What is the best js or code to use for the tooltip window that does not conflict with other magento js?

      The JS used for the window is part of a prototype based JS UI component library called Livepipe: We usually try to find JS plugins that are based on the Prototype library natively included in Magento. We don’t add jQuery (even though we’d prefer it) or any other JS frameworks to keep our JS footprint as light as possible.

      2 – How did you get your button to be next to your attribute? Is there an extension you’re using to visualize your attributes and allow you to insert the size button adjacent to it?

      We did extensive modifications to the site the example is from. Basically, the code showing the sizing guide button is added to the template that displays the configurable product options. It is part of the template customization and needs to be done manually for a specific template.

      The color/size swatches is an extension we developed specifically for this site. We looked at a third party extension (from this site: ) but didn’t like any of the offers so we did it ourselves. We also integrated a custom zoomify js for the product images. All in all, quite a bit of work. If you wish to discuss our services and how we could help you, please use the contact form on our LERO9 site (link in the footer) or send me an email to robert [at] this site domain.

  10. Tim Durham
    August 18, 2010 at 11:15 am /

    Without Ashely and Roberts insight I could not have gotten the sizing chart to show up like I wanted. I am not a programmer so I had to take their guidance and try to make it work for my site. It is not beautiful but it works. I summarized what I did for my test site here.

    I gave Ashely and Robert full credit since I could have done nothing without their input. I have tried a couple of approached on the color swatches but we will be going with the Color Swatches Plus with Thumbnails from . She had this example site: and that was really what I was looking for.


    Tim D.

  11. DVN
    September 9, 2010 at 4:47 am /

    Hi guys,

    Like Tim, I am attempting to create a dynamic link to a size guide (for example, size guides for “Dress Shirts & Sport Shirts” or “Tees & Knits” and so on). I have successfully made the attribute, and added it to an attribute set, but whenever the code into my view.phtml file, nothing appears – whether it’s the orginal code from Ashley’s awesome article, or Robert’s revised code.

    Any ideas?


    1. Robert
      September 9, 2010 at 10:39 am /

      First, let’s rule out the obvious: have you disabled the Magento cache or refreshed the cache after your phtml changes?

      If yes, and they are not appearing, have you made the change in the correct template file for the design your site is using?

      Provide the code you inserted and your attribute code. Use: < code > … < /code > (without the spaces) to enclose your code parts. You code blocks will look like this:
      < ?php echo $some_php_code; ?>

  12. DVN
    September 10, 2010 at 7:49 am /

    Hi Robert,

    Thanks for replying! I feel like a moron, but it was the cache, after turning them off I can see the changes. What I entered was:

    getAttributeText('fit_guide_template') == "mens_tees_knits"): ?>
    getLayout()->createBlock('cms/block')->setBlockId('mens_tees_knits')->toHtml() ?>

    However, like Tim – I have mutliple ‘Fit Guides’ that are dependent on the type of product on display (i.e., Sweater Fit guide for sweaters, trouser fit guide for trousers, etc.). I tried your code, but I can’t seem to make it work – would you suggest I just paste in the mutple php if statements?

    Thanks for your help – I’m more of a designer, so my PHP knowledge is limited (read: almost non existent!).


  13. DVN
    September 10, 2010 at 7:50 am /

    Cut my code off, let my try that again:

    ++++++++getAttributeText('fit_guide_template') == "mens_tees_knits"): ?>
    getLayout()->createBlock('cms/block')->setBlockId('mens_tees_knits')->toHtml() ?>

  14. Dave
    September 15, 2010 at 4:47 pm /

    Question regarding how you updated the availability. Magento seems to bundle the availability and pricing into one variable:


    How were you able to separate out the availability in pricing? Let me know if this question doesn’t make sense and I can try and re-word.

  15. Tim
    September 16, 2010 at 3:29 pm /

    I am revisiting this. I am really wanting to go with your code so that I don’t have to paste one for each sizing chart. cuz then I would have to modify the view.phtml file everytime I added a new sizing charge and the code on the page could get rather long just from the MANY sizing charts.

    I still can not get it to work. I have inserted this code on the page:

    getLayout()->createBlock('cms/block')->setBlockId($sizing_chart_id)->toHtml() ?>

    This is the message that is showing up on the page:

    Fatal error: Call to undefined function getAttributeText() in /home/userfolder/public_html/store/app/design/frontend/default/a050/template/catalog/product/view.phtml on line 125

    Any ideas on what I am doing wrong?


  16. Tim
    September 16, 2010 at 3:31 pm /

    It cut out my code !!!

    getLayout()->createBlock(‘cms/block’)->setBlockId($sizing_chart_id)->toHtml() ?>

    I inserted spaces in the php and div tags. Hopefully it will keep the code this time.

  17. Tim
    September 16, 2010 at 3:36 pm /

    <?php $sizing_chart_id = getAttributeText('sizing_chart');
    if ($sizing_chart_id) : ?>
    getLayout()->createBlock('cms/block')->setBlockId($sizing_chart_id)->toHtml() ?>

  18. Tim
    September 16, 2010 at 4:14 pm /

    It is working now. I had a buddy tell me that I simply needed to make this change:

    $sizing_chart_id = getAttributeText(‘sizing_chart’)

    $sizing_chart_id = $_product->getAttributeText(‘sizing_chart’)


    1. Eric
      December 10, 2010 at 7:55 pm /

      Great tutorial!!! I needed this for both custom sizing charts as well as custom availability just as your tutorial is setup. However it did not work right away. After a little playing with it I realized the problem lies in ‘if’ statement:
      getAttributeText(‘made_to_order’) == “Made to Order”): ?>

      I simply changed the php call from getAttributeText to getData and it works:
      getData(‘made_to_order’) == “1”): ?>

      Now I am off to try out the custom sizing charts. Also people if you are having similar problems test the output of your attribute by echoing it to the page and then fix the above if statement accordingly.

  19. Jen
    November 2, 2010 at 6:57 am /

    Hi! I am trying to implement size charts but no luck. I was going to post my question but don’t even know where to start… So I am going to post my code – I know it is wrong (because it’s not working). But I don’t know what to do at this point – have been trying to follow your posts for hours… Please help!!!

    In my case, I have a lot of products from various manufacturers. Every manufacturer has its own size chart. What I want is to be able to choose size chart ID from drop down attribute per product – in my code I am trying to display size chart named “casablanca” by the name of the manufacturer. My drop down attribute name is size_chart_template. And my static block’s name is casablanca.

    (I will add spaces to the code)

    getLayout()->createBlock(‘cms/block’)->setBlockId($size_chart_template)->toHtml() ?>

  20. Jen
    November 2, 2010 at 7:00 am /

    spaces in the code didn’t help. Trying again:

    < ?php getLayout()->createBlock('cms/block')->setBlockId($size_chart_template)->toHtml() ?>

  21. Jen
    November 2, 2010 at 7:02 am /

    getLayout()->createBlock(‘cms/block’)->setBlockId($size_chart_template)->toHtml() ? >

  22. Jen
    November 2, 2010 at 7:02 am /

    how do I post code here? spaces don’t help πŸ™

  23. Tim D
    November 2, 2010 at 7:18 am /

    I have never been able to post the code correctly on this page. I am not sure what is wrong. You may capture a screenshot and attach a JPG. That would quick and simple. Robert or Ashley will probably be able to look at it and tell you what is wrong.

    This function works very nice for me

  24. Jen
    November 2, 2010 at 7:21 am /

    hm.. I don’t see a place to attach images either πŸ™ Do i need to register with this forum to see more functions?

  25. DVN
    November 2, 2010 at 7:25 am /


    Why not use a site like to upload your image, and then link to it here?

  26. Jen
    November 2, 2010 at 7:40 am /

    Good idea!

    Here is direct link to my image with code:

    I am not good with PHP so the code is probably looking very ugly πŸ™‚

  27. Jen
    November 2, 2010 at 7:57 am /

    My code is giving me the error: Fatal error: Call to undefined function getattributetext() referring to the first line of the code. As I understand it means that I am trying to call for something that does not exist. Yes, I don’t have anything that is called $size_chart_template_id – and I am not sure what supposed to go here… Not sure how to read the code…

    I don’t have anything called $size_chart_template_casablanca either – but again, not sure what to put here…

    Any help is appreciated..

  28. ashley
    November 2, 2010 at 8:38 am /

    Looks like you’re missing the “$_product->” on getAttributeText() and the “$this->” getLayout() ?

  29. Jen
    November 2, 2010 at 8:44 am /

    Ok, the error is now gone. But it does not display anything… empty.
    Trying to past my new code… let’s see if it will let me:

    if ($size_chart_template_casablanca) : ?>
    $this->getLayout()->createBlock(‘cms/block’)->setBlockId($size_chart_template)->toHtml() ?>”

  30. Jen
    November 2, 2010 at 8:45 am /


    Ok, here is the picture with the code:

  31. Jen
    November 2, 2010 at 9:05 am /

    Can you please give me sample code with my attribute & block names? I think I am just messing things up because I am not sure how to read and apply the code.

    My attribute name is “size_chart_template”
    My static block name is “casablanca”

  32. Jen
    November 2, 2010 at 9:20 am /

    I did it! It works!!!! You made me think and I found the problem! Thanx a lot!

  33. Robert
    November 2, 2010 at 9:32 am /


    We’ve added improved code support in the comments now. Essentially you can use the <code>[your code here]</code> tags to enter code and/or HTML in the comments.

    To address your question: what value exactly are you putting in the “size_chart_template” attribute? You say it’s a drop-down attribute. Have you set values for it?

    The way I understand what you want to do is:

    Have a drop-down attribute you can assign to your products that contains the Static CMS block ID of the correct sizing chart.

    So, you would have your static CMS blocks set up with ID’s that match your manufacturers such as your “casablanca” one. I suggest you use some naming convention for your CMS blocks like: “sizing_casablanca”. You would enter this in the “Identifier” field on the CMS static block page.

    Your “sizing_chart_template” attribute would then have as one of its values: “sizing_casablanca”. Other values would be like: sizing_manufacturer_a, sizing_manufacturer_b, etc…

    Then, when editing your products, you would select the appropriate sizing chart identifier.

    On the product page phtml the code would be:

    < ?php // get the value of the sizing_chart_template attribute. If set, it should contain a valid Static CMS block identifier $sizing_cms_block_id = $_product->getAttributeText('sizing_chart_template');
    // check if set and only then display the block
    if ($sizing_cms_block_id) :
    echo $this->getLayout()->createBlock('cms/block')->setBlockId($sizing_cms_block_id)->toHtml();

    It’s important to set all the things up correctly first and don’t forget to disable or refresh the cache when testing.

  34. Jen
    November 2, 2010 at 9:38 am /

    Here is my working code:

    < ?php if ($_product->getAttributeText('size_chart_template') == "casablanca"): ?>
    < ?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('casablanca')->toHtml() ?>
    < ?php endif; ?>

    1. Robert
      November 2, 2010 at 9:47 am /


      This will work but it’s not very flexible. You are checking if your attribute has the value “casablanca” effectively hard-coding one specific attribute value for all your products, but this will not be the case for other sizing charts. Try to follow the steps outlined in my comment above to create a more flexible solution.

  35. Jen
    November 2, 2010 at 9:48 am /

    Maybe I am pushing my luck – but since you’re professional…

    Since I am inserting html data from static block via drop down attribute – sometimes there is too much info to be inserted into product page. What I am looking for is combining this code

    < ?php if ($_product->getAttributeText('size_chart_template') == "casablanca"): ?>
    < ?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('casablanca')->toHtml() ?>
    < ?php endif; ?>

    with this java script code

    Size Chart

    to get link that opens in a new window on click and displays the info that is in the block…

    Any idea? And let me know if my request is beyond what you can help me with…

    1. Robert
      November 2, 2010 at 9:59 am /


      What you are asking is beyond this tutorial. Basically, you could have an initially hidden div containing your sizing guide as per code above and then use javascript to show the div when a link is clicked.

      The won’t work in this case as you don’t have a “page” as such so you’d need to use a prototype plugin or library that can show arbitrary HTML in a popup – lightbox style. Magento already comes with the window.js library (/js/prototype/window.js) you can use to show popups.

      1. Jen
        November 2, 2010 at 10:01 am /

        Thank you! I will try and figure this out.

  36. Jen
    November 2, 2010 at 9:58 am /

    I got it working the “flexible” way! Thank you so much!!! Such a relief…

  37. duu
    December 6, 2010 at 12:52 pm /

    very useful tips!

  38. Sharon
    December 13, 2010 at 8:11 pm /

    I was trying to locate your full tutorial of how to do the size chart thing like Robert, but without any luck.
    Do you have the directions somewhere?

  39. Inessa
    February 2, 2011 at 3:58 am /

    Thanks, Great tips . Work for me

  40. Elemental
    March 21, 2011 at 2:12 pm /

    Thanks for the great tutorial.
    It is exactly what I am looking for.

    To play Devil’s Advocate:
    Using the Jean Sheepskin Low Boot example
    Is there a way you can select size standard (EUR, US/CAN,UK)
    Then based on that selection, see the appropriate size.

    For Example:
    Select Region: EUR > Select Size: 39,40,41 (in drop down menu)
    Select Region: US/CAN > Select Size: 8.5,9,9.5 (in drop down menu)

    I saw you were using ‘US 8’ in your size listings. I think
    implementing a conditional selector like this would take
    this example to the next level!

    Thanks again for sharing your knowledge!

  41. Eric
    July 16, 2011 at 2:14 pm /

    Perfect answer to my problem. My client wanted to quickly swap between items that her vendor wouldnt allow online sales aka “view only” and the normal magento product sale screen. Thanks!

  42. holly
    December 23, 2011 at 6:32 am /

    This helped a lot!
    I have this working with specific values for an attribute. Is there a way to have it show up ONLY if the value is Empty?

    1. Robert Popovic
      December 23, 2011 at 2:25 pm /

      Depending on what type of attribute you are checking for, often an empty attribute will contain “No” if the attribute is a multi select or drop-down so you could check for:

      if ('no' == strtolower(getAttributeText('my_attribute_code)) || !getAttributeText('my_attribute_code')) {
      // do your processing
      } else ...

      To make sure, you can just echo the attribute value and see what comes out when it’s blank and use that in your if statement.

  43. anoop
    December 26, 2011 at 11:11 pm /

    can anyone help me to get out an image editor in magento

  44. Hans
    April 27, 2012 at 8:15 pm /


    Thanks, great post! Does someone know how this works with a whole attribute set? If attributeset = X than show me this block?


  45. Reid B.
    Reid B.
    December 22, 2012 at 5:25 am /

    This isn’t exactly in-line with what you’re talking about – but I’ve taken this idea one step further, and made it so that instead of showing an item’s weight, you can show how much it will cost to ship it (if flat-rate) as a call-to action. The site I used this for is a kayak, canoe, & SUP retailer so they have large flat-rate freight shipments frequently. It is used in conjunction with a flat-rate plugin known as Webshopapps Matrix Rates:

    <?php if ($_product->getweight() > "155.0000" && $_product->getweight() < "187.0000"): ?>
            <?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('flat50')->toHtml() ?>
    <?php endif; ?>
    <?php if ($_product->getweight() > "186.0000" && $_product->getweight() < "208.0000"): ?>
            <?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('flat100')->toHtml() ?>
    <?php endif; ?>

    This simple snipit of code – if inserted properly on the view.phtml file – will return whatever you might have in each block respectively. So – say a smaller kayak between 155.0000 lbs and 187.0000 lbs is being viewed – it will show the customer that the item ships for $50 with a static-block call-out before they have to estimate shipping. Or – say they view a larger tandem boat – it will show the customer that it ships for a flat-rate of $100. This is a better incentive to buy than simply stating the weight of the boat (which is already stated within the product description).

  46. Anil
    April 10, 2013 at 5:30 am /

    I have a multi select attribute called “compostion”(having valid values like a,b,c etc). In my product page for Product X (having “composition” attribute set to a,b), i will like to show all other products name and price which have the same values in “composition” attribute(a,b).

  47. Mike
    July 11, 2013 at 7:16 pm /

    I can’t seem to get this to work in Magento

    I followed the steps very closely, but nothing happens. Anyone else using

  48. Mike
    July 11, 2013 at 8:47 pm /
    <?php if ($_product->getAttributeText('made_to_order') == "Yes"): ?>
        <p class="availability in-stock"><?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('made_to_order')->toHtml() ?>
    <?php endif; ?></span></p>
    <?php if ($_product->isAvailable()): ?>
        <p class="availability in-stock"><?php echo $this->__('Availability:') ?> <span><?php echo $this->__('In stock') ?></span></p>
    <?php else: ?>
        <p class="availability out-of-stock"><?php echo $this->__('Availability:') ?> <span><?php echo $this->__('Out of stock') ?></span></p>
    <?php endif; ?>
  49. Andy
    May 27, 2014 at 10:57 am /

    Does anybody know how to get multiple of these on a single product page, so my customers can purchase multiple variation of each product on without having to come back to the page. A table or matrix?

  50. Philipp
    January 7, 2015 at 8:21 am /

    how would you hide the delivery time for products that are out of stock?


Add a Comment & Join the Discussion

Insert small snippets of code by using [code]{your_code_here}[/code]
For larger code blocks please use and paste your link.

You may also use the following HTML in your comment: <a href="" title=""> <abbr title="">
<acronym title=""> <blockquote cite=""> <cite> <em> <strike> <strong>


This site uses Akismet to reduce spam. Learn how your comment data is processed.