1

Is there a way to show the terms and conditions on a page via .phtml? I have made a page via a module and now want to show the terms and conditions on that page.

  • Have you created terms and condition page via Content > Page and you want to display content of CMS page to your .phtml file? – Hitarth Pattani Mar 30 '18 at 12:27
  • Have you needed terms & condition content on your custom page right? – Abdul Mar 30 '18 at 12:30
  • @HitarthPattani Yes, I have created terms and conditions. Also they are visible via the check out. Furthermore, I have created a front end page on which I want to show the terms and conditions via a .phtml file which I included within the .xml file of the page I created (termsconditions_index_index.xml) – Bram Mar 30 '18 at 12:34
  • @Abdul Yes indeed, I want the terms and conditions to show on my custom page. – Bram Mar 30 '18 at 12:34
  • add your terms and condition in a static block and then add your static block to the phtml file, you can refer this answer – Piyush Mar 30 '18 at 12:37
3

Step:1 First add below code in your termsconditions_index_index.xml file.

<?xml version="1.0"?>

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceContainer name="content">
            <block class="Magento\CheckoutAgreements\Block\Agreements" name="terms_condition"  template="test/test.phtml"/>
        </referenceContainer>
    </body>
</page>

Step:2 Add below code in your .phtm file

<?php
/**
 * @var $block \Magento\CheckoutAgreements\Block\Agreements
 */
?>
<?php if (!$block->getAgreements()) {
    return;
} ?>
<ol class="agreements items">
<?php foreach ($block->getAgreements() as $agreement): ?>
    <li class="item">
        <?php if ($agreement->getIsHtml()):?>
            <?php /* @escapeNotVerified */ echo $agreement->getContent() ?>
        <?php else:?>
            <?php echo nl2br($block->escapeHtml($agreement->getContent())) ?>
        <?php endif; ?>
    </li>
<?php endforeach ?>
</ol>

Note: Please add your .phtml file path in termsconditions_index_index.xml

I have putted currently template="test/test.phtml"

After run below command:

php setup:di:compile
  • 1
    Wow you're amazing dude! I don't doubt that more people will need this in the future! Thanks man! – Bram Mar 30 '18 at 13:01
  • @bramulous Welcome :D – Abdul Mar 30 '18 at 13:03
  • @Abdul, in which path the file termsconditions_index_index.xml should be? – jafar pinjar Dec 6 '18 at 10:07
  • @jafarpinjar termsconditions_index_index is a custom module file for eg. app/code/AR/Termsconditions/view/frontend/layout/termsconditions_index_index.xml – Abdul Dec 7 '18 at 5:15
  • @Abdul, can you please share your module please? – jafar pinjar Dec 7 '18 at 6:17

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.