Block Method Calls in CMS Page - magento

Is there any a way to call Block method calls in CMS page?
What I am trying to do is. I have a hyperlink in my CMS Page and I want to retrieve the email address of the customer to pass it as a get variable which another website will use.
e.g. In CMS page I have
(someother website link)
<a href="www.xyz.com?email=<?php $getCutomer->getEmail();?>&&name=<?php $getCutomer->getName();?>
I know we can't add php in CMS pages or block. I have just shown you as an example what I want to achieve.
So is there any way using XML or anything else?
Please Advise. Thanks

Yes as MagePsycho said, you will need to create phtml file for calling block method or getting dynamic data.
In .phtml file, it's simple just call $this->getCustomerEmail() or whatever method you wrote to get customer email.

Why can't you simply include the .phtml file in CMS page or Static block as:
{{block type="core/template" template="path/to/your-custom-template.phtml"}}
and you can now use any php code in that .phtml file.
Cheers!

Related

Display template in front-end

I followed the tutorial of Inchoo for Magento
How to add custom contact form with email notification I added the files as mentioned now i need to know how to display it in front-end.
Tutorial link: inchoo.net/magento/magento-email/magento-custom-email-contact-form-with-notification-system/
Regards,
Add this in your cms page
{{block type="core/template" name="simple_contact_form" form_action="/inchoo-simplecontact/index/sendemail" template="inchoo/simple_contact.phtml"}}
Check app\code\local\Inchoo\SimpleContact\controllers\IndexController.php
there is sendemailAction() and in it at last $this->_redirect('inchoo-simplecontact/'); this will redirect. So may you want to change redirect it's here.

How to call Cms Block content and html in controller file back end magento2

I'm Working with magneto 2. I want to get cms block content in my custom module controller file.
I want to know to Get the my custom module controller file. i'm not able to do.
i have used code
echo $this->getLayout()->createBlock('cms/block')->setBlockId('block_identifier')->toHtml();
inside my controller but code is not working.
How can I do?
Try with below block code.
echo $this->_view->getLayout()->createBlock('Magento\Cms\Block\Bl‌​ock')->setBlockId('y‌​our_block_id')->toHt‌​ml();

How to create sub pages in magento?

I am working on Magento. I want to create a sub pages of cms page and sub pages will be shown in sidebar Let me know how can I do this?
I want sub pages as given in screen-shot:- http://awesomescreenshot.com/09c5rfnr41
I would like to inform you that hierarchy feature is not available in Magento Community version.
But I feel that you can achieve your requirement by using this extension https://www.magentocommerce.com/magento-connect/page-summary-block.html
Thanks!
Follow these steps:
Login to admin and navigate to CMS -> Pages.
Create new page.
Add URL Key as main-url/sub-url for example if your main page url is aboutus then sub page will be look like aboutus/aboutus-sub
To add those links to left sidebar, you should create phtml file in your theme template folder and call that phtml file from appropriate xml file.
<reference name="left">

Load magento view via ajax?

I have the folliwng file:
app/design/frontend/default/site/template/checkout/cart/cartheader.phtml
I want to load this in via ajax, so that when the cart is updated, we can trigger an ajax call to get the contents of this file and update the page on the fly.
Does anybody know how I can access this file via ajax or even just from my browser so I can see the contents?
Thank you
You need to create a new controller with methods from CartController.php this controller can be found in app/code/core/Mage/Checkout/controllers . The methods to add and remove items from cart should be changed to use ajax and return json. The json returned can have the session messages - global messages block and cart header block, maybe other blocks depending on all info you want to update.
app/design/frontend/default/site/template/checkout/cart/cartheader.phtml is from the enterprise theme and is the template for the block Mage_Checkout_Block_Cart_Sidebar. This template is set inside layout/checkout.xml
<block type="checkout/cart_sidebar" name="cart_sidebar" as="topCart" template="checkout/cart/cartheader.phtml">...</block>
To get it from a controller you can add it to the layout xml of that controller, or use:
$this->loadLayout()->getLayout()->createBlock('checkout/cart_sidebar')->toHtml();
But inside Enterprise, this block already loads using ajax.

Magento - create a module with simple .phtml template

I want to create a module with simple .phtml template, that have to be included in the page "cart.phtml" and also in "noItems.phtml"
How can do that ?
Thanks a lot.
You can create a simple module as shown in this >> tutorial.. and once you finished the weblog example in the above link, you can take a look at this link >> to create and place a phtml file.
Balan

Resources