0

I need help, please.

  • I created a cms page with id=terms
  • I insert in the content of web page this code:

    {{block class="Magento\Framework\View\Element\Template" template="Magento_Theme::test/test.phtml"}}
    
  • I create the test.phtml file in folder:

    public_html/app/design/frontend/VENDOR/THEME/Magento_Theme/templates/test

  • Into test.phtml I insert the code:

    <?php echo "Hello World!"; ?>;
    

All it's alright. The output of www.dominio.com/terms is "hello world".

Now I would like changing the php code for display the Terms and Conditions configured in STORE, SETTINGS.

Can you help me, please?

Thanks

1
  • Where is this store settings ? – PЯINCƏ Aug 7 '18 at 20:41
0

If I understood correctly you want to get in your phtml the content of your termes & conditions set in Stores > under Settings > Terms and Conditions.

So 1st solution and the best is to add some function in your block module then you get that function in your phtml to avoid using directly the objectManager in a phtml, 2nd solution you can do it direclty in phtml without a block but it is not recommended.

1st solution:

app/code/{Vendor}/{Module}/Block/agreements.php

<?php
namespace {Vendor}\{Module}\Block;
class agreements extends \Magento\Framework\View\Element\Template
{
    protected $_agreements;

    public function __construct(
        \Magento\Framework\View\Element\Template\Context $context,
        \Magento\CheckoutAgreements\Model\Agreement $agreements
    )
    {
        $this->_agreements = $agreements;
        parent::__construct($context);
    }

    public function getAgreements($agreementId)
    {
        $agree =  $this->_agreements->load($agreementId);
        return $agree->getContent();
    }
}

in test.phtml you add this :

<?php echo $this->getAgreements(1); ?> //1 is the termes & conditions ID

2nd solution

test.phtml

<?php $objectManager = \Magento\Framework\App\ObjectManager::getInstance();?>
<?php $agreements = $objectManager->create('Magento\CheckoutAgreements\Model\Agreement')->load(1);?> //here 1 is the ID of your termes & conditions.
<?php echo $agreements->getContent();?>
1
  • hi @Prince, can you please explain in detail? can we show terms and condtions from cms block in checkout? – jafar pinjar Dec 11 '18 at 8:04

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.