Magento – How to Get Product Attribute to JavaScript

attributesjavascriptproductstatic-block

I'm making and slide in function to that product page. So when you are close to the bottom a static block will come visible.

That static block should have a link to an article the link is different from product to product and is set in by a custom product attribute.

The problem is to get that custom attribute into my .js can you help?

What I've done so far

  1. Call in an custom.js in page.xml
  2. Make static block, and call it in at the bottom on view.phtml

custom_att name is article link
The js have only the "do somthing when you are close to bottom" function right now

jQuery(window).scroll(function() {
   if(jQuery(window).scrollTop() + jQuery(window).height() > jQuery(document).height() - 100) {
       alert("near bottom!");
   }
})

Best Answer

You can place this JS code anywhere to product page :

<script type="text/javascript">
    var article_link = "<?php echo $product->getArticleLink() ?>";
</script>

Now you can use javascript variable article_link anywhere on .js file, in your case it's custom.js

Related Topic