Question

I created an attribute called "youtube" (text field only) on magento. In this text field I put youtube video urls like (www.youtube.com/embed/nk_FpiXp-3s) etc...

So my issue is I`m trying to php echo this attribute "youtube" inside my html href code.

 <a class="various fancybox.iframe" href="<?php echo $_product->getAttributeText('youtube')?>">Youtube (iframe)</a>

but it seems to break the page. Also my fancybox script.

<script>
   var $j = jQuery.noConflict();
   $j(".various")
       .attr('rel', 'gallery')
       .fancybox({
       openEffect  : 'none',
       closeEffect : 'none',
       nextEffect  : 'none',
       prevEffect  : 'none',
       padding     : 0,
       margin      : [20, 60, 20, 60] // Increase left/right margin
   });
</script>    

Any tips guys ? It's custom attribute inside of a custom block. The block on product page is working fine so the issue is on php echo.

Thanks!

Sorry for the missing (?>) but it seems to not be working.

Was it helpful?

Solution 2

Use the code below

<?php echo $_product->getYoutube(); ?>

OTHER TIPS

Hello Check below code may be help you

$_product->getData('youtube');

OR

$attributes = $_product->getAttributes();

$attributes['youtube']->getFrontend()->getValue($_product);

Given that your PHP is totally invalid, by never closing the <?php tag. Perhaps you want something more like (split over multiple lines for legibility):

<a
 class="various fancybox.iframe"
 href="<?php echo $_product->getAttributeText('youtube') ?>">
                                                       ^^^---missing
 Youtube (iframe)</a>

I found the solution...

html:

    <?php $_product = $this->getProduct(); ?>
    <?php if($_product->getVideobox()): ?>
    <a class="fancybox fancybox.iframe" href="http://www.youtube.com/embed/<?php echo    $_product->getVideobox(); ?>">video<a/>
    <?php endif; ?>

script:

<script>
 var $j = jQuery.noConflict();
   $j(".fancybox")
   .attr('rel', 'gallery')
   .fancybox({
   openEffect  : 'none',
   closeEffect : 'none',
   nextEffect  : 'none',
   prevEffect  : 'none',
   padding     : 0,
   margin      : [20, 60, 20, 60] // Increase left/right margin
   });
  </script>       

Videobox = attribute code

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top