How to put php syntax on cms page in Magento - magento

How can I put a php code on cms page in Magento?
Image here: http://screencast.com/t/COgHigLih7
I want to put
<?php
echo "Test";
?>

You can not add php code directly into the content of a cms page
What you could do is add your php code into a pthml and then call it from you cms page
{{block type="core/template" name="contactForm" template="contacts/my_php_code.phtml"}}

Related

Magento how to call phtml file as a block on cms page?

I am using magento 1.9.1 and trying to create a product link directly on cms page.I have created a custombutton.phtml file and add button code here.
<?php $formKey = Mage::getSingleton('core/session')->getFormKey(); ?>
<a class="animated infinite swing btn btn-yellow btn-lg m-r-2" role="button" href="abc.com/checkout/cart/add?product=401&qty=1&form_key=<?php echo $formKey ?>">Add to cart</a>
Now i am calling this phtml file as block on cms page.
{{block type="core/template" name="custombutton" template="custombutton.phtml"}}
But sometimes it is showing button and sometimes not. Not getting the issue.
Please give rights to block goto->system->permissions->block
and add your block name. Hope this helps

Magento how add product to static cms module page

I have magento with cms module and I created static page, now I would like to add a some of products to this page.
How can I do that?
i've found this plugin http://www.fmeextensions.com/magento-add-products-to-cms.html but i want to do it by myself
You can add products from a category to a CMS page by ading this to your cms content - disable the wysiwyg editor when you paste it in;
{{block type="catalog/product_list" category_id="123" template="catalog/product/list.phtml"}}
Just change the category ID to the one you want.

Get recently viewed products in magento home page

How to get recently viewed products in magento.
I tried the following code also
$this->getRecentlyViewedProducts();
in the file product_viewed.phtml
1.Place code snippet below in any template u want to add
<?php echo $this->getLayout()->createBlock('reports/product_viewed')->setTemplate('reports/product_viewed.phtml')->toHtml(); ?>
2.Place code snippet below in any Backend cms-> page or static block
{{block type="reports/product_viewed" template="reports/product_viewed.phtml"}}
Replace template name, product_viewed.phtml with your site.

how to show recent view products on home page in magento

I want to how recently viewed products on home page in magento.
Currently I am using below code but this is now working. so please help!!
getLayout()->createBlock('reports/product_viewed')->setTemplate('reports/product_viewed.phtml')->toHtml(); ?>
Did you forget to echo?
<?php echo $this->getLayout()->createBlock('reports/product_viewed')->setTemplate('reports/product_viewed.phtml')->toHtml(); ?>
By the way if you're doing it from the CMS you need to use:
{{block type="reports/product_viewed" template="reports/product_viewed.phtml"}}

How to call a cms page in a phtml file in magento?

I need to display a CMS page inside my custom module's phtml file. Is there any way I can include it either through xml layout or via coding directly in phtml file? I know we can add a cms block but how can we add a cms page?
Try the below code in your phtml file
$page = Mage::getModel('cms/page')->load('home_page','identifier');
echo $page->getContent();
This code check if cms page is active then it will display page content
$page = Mage::getModel('cms/page')->load('top_offer','identifier');
echo $page->getIsActive()?$page->getContent():'';

Resources