Solved

Modify PHP to show the HTML instead of the code

Posted on 2010-11-16
16
563 Views
Last Modified: 2012-05-10
I am working with Magento and have figured out how to get a particular variable to show on the grouped product display page, but am not sure since my PHP skills are slim to none on how to get it not show the code and recognize the code that is there so that it will display correctly.  Currently it displays on the code.  I'm pretty sure it's the htmlEscape, but I don't know what else to use.  Below is the code and the line I am referring to is the getShortDescription:

<td><?php echo $this->htmlEscape($_item->getName()) ?></td>
                  <td><?php echo $this->htmlEscape($_item->getShortDescription()) ?></td>
            <td class="a-right">
                <?php echo $this->getPriceHtml($_item, true) ?>
                <?php echo $this->getTierPriceHtml($_item) ?>
            </td>
            <?php if ($_product->isSaleable()): ?>
            <td class="a-center">
            <?php if ($_item->isSaleable()) : ?>

Thanks in advance!
0
Comment
Question by:kmurphychi
  • 6
  • 4
  • 2
  • +3
16 Comments
 
LVL 7

Expert Comment

by:armchang
ID: 34152334
Hi,

One way to do is to call javascript window.open function and passing it the all the well-formed html code inside it. This example pops-up a window on page exit/unload:

<html>
<head>
 <title>JavaScript Popup Example 3</title>
</head>
<SCRIPT language="JavaScript1.2">
function exitpop()
{
my_window= window.open ("",
  "mywindow1","status=1,width=350,height=150");
my_window.document.write('<H1>Popup Test!</H1>');
}
</SCRIPT>
<body onunload="javascript: exitpop()" >
<H1>JavaScript Popup Example 4</H1>
</body>
</html>
0
 

Author Comment

by:kmurphychi
ID: 34152353
Unfortunately this is not a viable option.  I am trying to not have to hack too much of the core code of Magento, so that would be the safest bet for me to have the html code displayed instead of it stripping it, but thanks for the tip!
0
 
LVL 6

Expert Comment

by:ahdfx
ID: 34152546
What is the name of the file that is being loaded?
0
 

Author Comment

by:kmurphychi
ID: 34152555
Do you mean the magento file?  If so it is group.phtml
0
 
LVL 30

Expert Comment

by:Marco Gasi
ID: 34152689
Try to use html_entity_decode() instead of htmlEscape.

Cheers
0
 
LVL 6

Expert Comment

by:ahdfx
ID: 34152779
If I am understanding correctly.  You are trying to get group.phtml to process PH code?  Is that correct?
if so, you need to modify the htaccess file to process phtml as php.  If that is not what you are trying to accomplish...  Then I don't know what you are trying to do.
0
 
LVL 6

Expert Comment

by:V4nP3rs13
ID: 34155065
<?php
$file = "include.php"; //put your file path here
echo str_ireplace(array("<", ">"), array("&lt;", "&gt;"), file_get_contents($file));
?>
0
 

Author Comment

by:kmurphychi
ID: 34155609
I think the html_entity_decode()should work, but do I write it as <td><?php echo $this->html_entity_decode()($_item->getShortDescription()) ?></td>  ?  If so it's not working.
0
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
LVL 108

Expert Comment

by:Ray Paseur
ID: 34155707
Where is the test URL that shows the error in action?  I'll take a look.  Thanks, ~Ray
0
 

Author Comment

by:kmurphychi
ID: 34155991
http://mrrhythmschildrensmusic.com/magento/index.php/childrens-music-1/mr-rhythm-s-zoo.html
Here it is with the <td><?php echo $this->html_entity_decode()($_item->getShortDescription()) ?></td> for which I get a parse error syntax.  If the line is <td><?php echo $this->htmlEscape($_item->getShortDescription()) ?></td> it spits out the code instead of the HTML as it should be.

If you need the entire code for the page, it is here:  Thanks so much for all of your help!
<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE_AFL.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category    design
 * @package     base_default
 * @copyright   Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
 * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */

/**
 * Grouped product data template
 *
 * @see Mage_Catalog_Block_Product_View_Media
 * @see Mage_Catalog_Block_Product_View_Type_Grouped
 */
?>
<?php $_product = $this->getProduct() ?>
<?php $_associatedProducts = $this->getAssociatedProducts() ?>
<?php if($_product->isSaleable() && count($_associatedProducts)): ?>
    <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; ?>
<?php echo $this->getChildHtml('product_type_data_extra') ?>
<table class="data-table grouped-items-table" id="super-product-table">
    <col />
    <col />
    <col width="1" />
    <thead>
        <tr>
            <th><?php echo $this->__('Product Name') ?></th>
                  <th><?php echo $this->__('Sample The Music') ?></th>
            <th class="a-right"><?php echo $this->__('Price') ?></th>
            <?php if ($_product->isSaleable()): ?>
            <th class="a-center"><?php echo $this->__('Qty') ?></th>
            <?php endif; ?>
        </tr>
    </thead>
    <tbody>
    <?php if (count($_associatedProducts)): ?>
    <?php foreach ($_associatedProducts as $_item): ?>
        <?php $_finalPriceInclTax = $this->helper('tax')->getPrice($_item, $_item->getFinalPrice(), true) ?>
        <tr>
            <td><?php echo $this->htmlEscape($_item->getName()) ?></td>
                  <td><?php echo $this->html_entity_decode()($_item->getShortDescription()) ?></td>
            <td class="a-right">
                <?php echo $this->getPriceHtml($_item, true) ?>
                <?php echo $this->getTierPriceHtml($_item) ?>
            </td>
            <?php if ($_product->isSaleable()): ?>
            <td class="a-center">
            <?php if ($_item->isSaleable()) : ?>
                <input type="text" name="super_group[<?php echo $_item->getId() ?>]" maxlength="12" value="<?php echo $_item->getQty()*1 ?>" title="<?php echo $this->__('Qty') ?>" class="input-text qty" />
            <?php else: ?>
                <p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
            <?php endif; ?>
            </td>
            <?php endif; ?>
        </tr>
    <?php endforeach; ?>
    <?php else: ?>
       <tr>
           <td colspan="<?php if ($_product->isSaleable()): ?>4<?php else : ?>3<?php endif; ?>"><?php echo $this->__('No options of this product are available.') ?></td>
       </tr>
    <?php endif; ?>
    </tbody>
</table>
<script type="text/javascript">decorateTable('super-product-table')</script>
0
 
LVL 30

Expert Comment

by:Marco Gasi
ID: 34156027
You should write so:

<td><?php echo $this->html_entity_decode(($_item->getShortDescription())) ?></td>  ?>

Cheers
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 34156119
I see this:

Parse error: syntax error, unexpected '(', expecting ',' or ';' in /home/mrrhythm/public_html/magento/app/design/frontend/base/default/template/catalog/product/view/type/grouped.phtml on line 62


You might want this:

<td><?php echo html_entity_decode($_item->getShortDescription()) ?></td>

It would be helpful to see the "view source" from this:

var_dump($_item->getShortDescription());
0
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 34156130
Or it might need to be this - with the semicolon.  Not sure but I would use the semi-colon, I think.

<td><?php echo html_entity_decode($_item->getShortDescription()); ?></td>
0
 

Author Closing Comment

by:kmurphychi
ID: 34156154
Hurray!!  It worked.  Thank you so much!  I really appreciate all of your help.
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 34156254
Great!  Thanks for the points.  

Going forward, when you post code here at EE, please use the code snippet.  It gives us line numbers and a uni-space font that is very easy to read.

best of luck with your project, ~Ray
0
 

Author Comment

by:kmurphychi
ID: 34156266
You've got it.  Thanks again!
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now