0

I need help to verify my if statement, I am not sure in Magento of using "$block->escapeHtml($label)" in if condition is correct or not

does my if statement correct for only showing "Card Number" & "Card Type" info?

thanks!

<?php if ($block->escapeHtml($label) == 'Card Number') || ( $block->escapeHtml($label) == 'Card Type') {?>

/module-payment/view/frontend/templates/info/default.phtml

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

/**
 * @var \Magento\Payment\Block\Info $block
 * @see \Magento\Payment\Block\Info
 */
$specificInfo = $block->getSpecificInformation();
$title = $block->escapeHtml($block->getMethod()->getTitle());
?>
<dl class="payment-method">
    <dt class="title"><?= /* @noEscape */ $title ?></dt>
<?php if ($specificInfo) : ?>
    <dd class="content">
        <table class="data table">
            <caption class="table-caption"><?= /* @noEscape */ $title ?></caption>
            <?php foreach ($specificInfo as $label => $value) : ?>
                <?php if ($block->escapeHtml($label) == 'Card Number') || ( $block->escapeHtml($label) == 'Card Type') {?>
                <tr>
                    <th scope="row"><?= $block->escapeHtml($label) ?></th>
                    <td>
                        <?= /* @noEscape */ nl2br($block->escapeHtml(implode("\n", $block->getValueAsArray($value, true)))) ?>
                    </td>
                </tr>
                <?php } ?>
            <?php endforeach; ?>
        </table>
    </dd>
<?php endif;?>
</dl>
<?= $block->getChildHtml() ?>
1
  • <?php if ($label == 'Card Number') || $label == 'Card Type') {?> try this Aug 18, 2021 at 6:05

1 Answer 1

1

Try this code :

<?php if($block->escapeHtml($label) == 'Card Number' || $block->escapeHtml($label) == 'Card Type') {?>
2
  • Hi! thank you for pointing out my careless mistake. but inside the condition, I should use "$block->escapeHtml($label)" or just "$label" ?
    – Paul Fan
    Aug 18, 2021 at 15:40
  • You can use escapehtml. If answer help then upvote and mark as solution, so it will help others in community. Aug 18, 2021 at 15:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.