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 PattaniCommented Mar 30, 2018 at 12:27
-
Have you needed terms & condition content on your custom page right?– AbdulCommented Mar 30, 2018 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)– CondorCommented Mar 30, 2018 at 12:34
-
@Abdul Yes indeed, I want the terms and conditions to show on my custom page.– CondorCommented Mar 30, 2018 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– PiyushCommented Mar 30, 2018 at 12:37
|
Show 5 more comments
1 Answer
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
-
1Wow you're amazing dude! I don't doubt that more people will need this in the future! Thanks man!– CondorCommented Mar 30, 2018 at 13:01
-
-
@Abdul, in which path the file termsconditions_index_index.xml should be? Commented Dec 6, 2018 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– AbdulCommented Dec 7, 2018 at 5:15
-