- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ciao a tutti,
ho un piccolo problema, sono sicuro che voi esperti potete aiutarmi.
Su alcuni articoli ho la necessità di collegare un file PDF da far scaricare ai clienti.
Allora ho richiamato un nuovo attributo nella pagina prodotto (con una icona grafica), ma vorrei che questo attributo apparisse solo SE CONTIENE UN VALORE (url al link pdf).
Attualmente, l'attributo viene visualizzato su tutti gli articoli, anche se l'attributo non contiene un valore. Sicuramente, con un IF posso risolvere questo problema.
questo è il codice che sto usando in questo momento:
<a href="<?php echo $this->helper('Magento\Catalog\Helper\Output')->productAttribute($block->getProduct(), $block->getProduct()->getAttributeId(), 'attribute_id'); ?>" target="_blank" /> <?php echo("<img src=\"https://PATH-ICONA.png\">")?> </a>
spero in un vostro aiuto.
è un codice che può servire a molti per diverse customizzazioni.
grazie in anticipo
Solved! Go to Solution.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You need to set if conditions for whether value is set or not?
<?php if ($block->getProduct()->getAttributeId()){ ?> <a href=" <? php echo $this -> helper ( 'Magento \ Catalog \ Helper \ Output' ) -> productAttribute ( $ block -> getProduct (), $ block -> getProduct () -> get AttributeId () , ' attribute_id ' ); ?> "target =" _ blank "/> <? php echo ( "<img src=\" https: // PATH-ICONA.png \ ">" )?> </a> <?php } ?>
Magento 2 Blogs/Tutorial
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You need to set if conditions for whether value is set or not?
<?php if ($block->getProduct()->getAttributeId()){ ?> <a href=" <? php echo $this -> helper ( 'Magento \ Catalog \ Helper \ Output' ) -> productAttribute ( $ block -> getProduct (), $ block -> getProduct () -> get AttributeId () , ' attribute_id ' ); ?> "target =" _ blank "/> <? php echo ( "<img src=\" https: // PATH-ICONA.png \ ">" )?> </a> <?php } ?>
Magento 2 Blogs/Tutorial
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: Richiamare un Attributo nella pagina prodotto
VERY GOOD. many thanks