How to put PHP inside an echo?

Asked

Viewed 3,872 times

1

How do I stop instead:

elseif ( $qtd == 1000 ) {
    echo $this->__('<b>produto customizável</b><br><span class="product-name">ENTRE EM CONTATO</span><div style="backgroud:#333">');    
}

Make it work that:

elseif ( $qtd == 1000 ) {
    echo $this->__('<a class="askproduct popup" href="<?php echo Mage::getUrl('askfordetails/askfordetails', array('product_id' => $_product->getId())) ?>"><?php echo Mage::helper('askfordetails')->__('ENTRE EM CONTATO') ?></a>');  
}

Does anyone know if this is possible?

  • This post is the excerpt of a conditional, that if the stock of a given product is equal to 1,000 is to show on the front a link composed by the base url + /askfordetails/askfordetails/index/product_id/ + the product id

  • see all code snippet: <? php $Qtd = Mage::getModel('cataloginventory/stock_item')->loadByProduct($product)->getQty(); if ( $Qtd == 0 ) { echo $this->('<span class="product-name">PRODUCT<br>OUT OF STOCK</b>');} elseif ( $Qtd == 1000 ) { echo $this->_('<b>customizable product</b><br><span class="product-name">MAKE CONTACT</span><div style="backgroud:#333">'); } Else { ? > <? php echo $this->getChildHtml('product_type_data') ? > <? php echo $this->getChildHtml('addtocart') ? > <? php } ?>

  • Why do you keep opening and closing PHP instead of using only one <?php up there and a ?> underneath?

  • I’m pretty clueless in PHP, I don’t know why I’m like this. All I know is that I’ve been searching the internet for a solution for this and I can’t find it, I’ve read enough about concatenating php inside echo, but I can’t execute it!! you know how this should look?

  • 1

    He’s so full of trouble, it’s hard to even begin to answer. Look, I rewrote your code in a more normal way, but I didn’t get implementation errors, which depend on the rest of your system: http://pastebin.com/mnPF8Dgw - It would be nice to get at least a basic notion of what you are doing, or even with good answers, you will have trouble applying to your practical case.

  • Thank you, Bacco. I know that!

  • In summary, you can give several "echo" in separate lines without concatenating. echo '1'; echo '2'; echo '3'; even in separate lines will exit 123 on the screen. Or if you prefer, you can use the dot: echo Funcao1() . Funcao2() concatenation. Another example: echo 'x'.(2+2).'y'; will show x4y onscreen.

  • This I understood, but I still can’t display it:<a class="askproduct popup" href="<? php echo Mage::geturl('askfordetails/askfordetails', array('product_id' => $product->getId())) ? >"><? php echo Mage::helper('askfordetails')->_('GET IN TOUCH') ? ></a> instead: <b>customizable product</b><br><span class="product-name">CONTACT</span><div style="background:#333">

  • Edit the question by clicking on [Edit] just below it, put all the details you need, and learn how to format your questions here: http://answall.com/editing-help - Read also [Ask] to be able to improve your posting, thus increases the chance of being able to help.

  • http://pastebin.com/z4davmkh

  • It hasn’t worked yet, but anyway, thank you very much Bacco! I’ll study a little about concatenating and breaking the head more. Thanks a lot

Show 6 more comments

1 answer

13

Just use concatenation. If you want to display dynamic content inside echo, use concatenation. In your case it would be:

elseif ( $qtd == 1000 ) {
    echo $this->__('<a class="askproduct popup" href="'.Mage::getUrl("askfordetails/askfordetails", array("product_id" => $_product->getId())).'">'.Mage::helper("askfordetails")->__("ENTRE EM CONTATO").'</a>');  
}

What was used there is simple to understand, rather than to do:

echo '<a href="<?php echo $variavel?>">Clique aqui</a>';

I’ll tell you what:

echo '<a href="'.$variavel.'">Clique aqui</a>';
  • 1

    One more case that the answer saves the question +1

Browser other questions tagged

You are not signed in. Login or sign up in order to post.