?
Solved

Modify PHP to show the HTML instead of the code

Posted on 2010-11-16
16
Medium Priority
?
590 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

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

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
 
LVL 111

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 31

Expert Comment

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

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

Cheers
0
 
LVL 111

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 111

Accepted Solution

by:
Ray Paseur earned 2000 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 111

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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
This article discusses how to implement server side field validation and display customized error messages to the client.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Suggested Courses
Course of the Month16 days, 6 hours left to enroll

850 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