I'm using the BannerSlider Extension and it works great but for design purposes I need it to include it in a template.
At this moment I'm using it with the CMS like this:
{{block type='bannerslider/bannerslider' template='bannerslider/bannerslider.phtml'}}
How can I get the PHP code for that single line, to add it directly to my template ?
Create cms/block and place your code
{{block type='bannerslider/bannerslider' template='bannerslider/bannerslider.phtml'}}
and then you can call anywhere in template that cms/block like this
<?php
echo $this->getLayout()->createBlock('cms/block')->setBlockId('YOUR IDENTIFIER')->toHtml()
?>
Related
I use wordpress and ACF. I use $link in the template, for example:
$link = get_field('custom_link');
After that, I wrote a code that checks the url for identifiers and if there are matches, then replaces $link['url'], $link['title'] and $link['target'] with "options".
Next comes:
<?php echo esc_html($link_title); ?>
This all works in a build, but I'm trying to use the same code on all links in all templates, so I created a "links.php" file and pasted my link checking code in there.
In the template, I tried to call the file with get_template_part and include. Also, I've tried include(locate_template('links.php')), but that doesn't work either.
Can someone tell me how to properly use repeatable code in ACF templates?
Everything worked using:
include(locate_template('folder1/links.php'));
The template was located in the folder with the theme in "folder2", and the link file in "folder1".
Before that, I tried:
include(locate_template(' ../folder1/links.php'));
and various variations, but I did not think that the path is taken from the theme folder.
I have a short code
{{block type="ibtheme/product_list_featured" category_id="51" random_products="" template="catalog/product/list/featured.phtml"}}
which is working fine in editor from backend. How can U call the same short-code from a PHTML page ?
When I put the same code, it is printing a simple text.
phtml is php code, not cms html passed through a filter to catch the short codes (macros) and expand them out.
The contents between "{{" and "}}" must interpreted by a template engine and is only valid inside emails, CMS pages/blocks and the wysiwyg editors in the backend.
You put their equivalent into layout and call them as in the following ->
Magento Shortcode CMS block not working on product pages
In Magento CMS or Static block, if you want to add PHP code then you can just call any custom .phtml file by using following code. Like here I am including my_custom.phtml.
{{block type="core/template" name="myCustom" template="cms/my_custom.phtml"}}
This is equivalent to following layout tag:
<block type="core/template" name="myCustom" template="cms/my_custom.phtml">
Hope you find it useful.
The above answers are both incorrect if I'm reading that you would like to use shortcodes in phtml pages. I use these frequently, since we have a tremendous amount of content, and breaking them down in to phtml blocks is the easiest way for us to keep our content fresh.
Anyhow, here's the correct way to use call blocks in phtml:
<?php echo $this->getLayout()->createBlock('core/template')->setTemplate('cms/my_custom.phtml')->toHtml(); ?>
For Example, to use the block in your original answer would be
<?php echo $this->getLayout()->createBlock('ibtheme/product_list_featured')->setTemplate('catalog/product/list/featured.phtml')->toHtml(); ?>
I think this is what you're actually looking for. The code is in the CMS module in the Magento code.
<?php
// Load the cms helper
$helper = Mage::helper('cms');
// get the cms static block processor
$processor = $helper->getBlockTemplateProcessor();
// run the content with the shortcode through the filter
// in this case $item->getAnswer() contains a shortcode
$html = $processor->filter($item->getAnswer());
// print it to the page
echo $html;
?>
Remember anything is possible, just dig deeper. If in doubt, copy the Magento core code.
This is the first time I am creating a custom tempalte for Magento. I installed a 3rd party plugin, that allows me to use this code in the cms editor:
{{block type='bannerslider/bannerslider' template='bannerslider/bannerslider.phtml'}}
Now, I want to use this on a page in my template. What php code should I use to get this to work ?
I tried
<?php echo $this->getChildHtml('bannerslider/bannerslider') ?>
But that displays nothing.
Thank you!
You have to declare your block inside layout file of your custom template (usually, local.xml) under some handle (like default or catalog_product_view).
For example:
<block type="bannerslider/bannerslider" name="banner_home" template="bannerslider/bannerslider.phtml"/>
under <default> handle would let you to call <?php echo $this->getChildHtml('banner_home') ?> in any place of your template. Notice that you have to use name from layout, not block class to call it with getChildHtml.
An alternative I received from someone else:
<?php echo $this->getLayout()->createBlock('bannerslider/bannerslider')->setTemplate('bannerslider/bannerslider.phtml')->toHtml();
?>
I'm using Magento.
I want display and call one phtml file as a link in another phtml file…
I have the new.phtml file on the home page. On that I put one link CHECK ALL which display all new products as category page.. It looks like category page. For that I create another phtml file named newproductpage.phtml which has same code of new.phtml. Now I try to call this newproductpage.phtml file #homepage as CHECK ALL link for that I write this code....
CHECK ALL
But its not working....
thnx..
you call newproductpage.phtml in any phtml file using below code
<?php echo $this->getLayout()->createBlock('core/template')->setTemplate('custom/newproductpage.phtml')->toHtml(); ?>
Use the below code for rendering your phtml file in another phtml file.
<?php echo $this->getLayout()->createBlock('core/template')->setTemplate('templatefolderpath/filename.phtml')->toHtml(); ?>
For more refinement of your code, you can use the block name and block file name instead of core/template because core/template use the core resources.
You can not call directly one phtml file to another phtml file.
But there are two way to call your phtml file either create one controller and create one action and call action from your anchor tag or create one cms page which call your phtml file.
if you create one module, so in your layout file something you can write
<modulename_controllername_controlleraction>
<reference name="content">
<block type="catalog/product_new" template="custom/newproductpage.phtml" />
</reference>
</module_controllername_controlleraction>
Or you can directly put this code in your cms page content area
{{block type="catalog/product_new" template="custom/newproductpage.phtml"}}
and in anchor tag give cms page link.
<?php echo $this->getLayout()->createBlock('core/template')->setTemplate('catalog/product/new.phtml')->toHtml(); ?>
you can also check the link.
Display .phtml page in another .phtml page
I believe you and I want to do precisely the same thing. I'm creating a modal from bootstrap and I need to call in a partial using the href attr.
So far, I think this might be possible by creating a page in the CMS and then using something like this:
<li>Home</li>
But honestly, I'm just starting out with Magento and know very little.
you can use iframe for same and load this another page content using AJAX call
I'm running magento 1.4 and I'm trying to display an overlayer banner on all the pages in my magento store. In which file should I add the code snippet for the banner so that the it gets displayed on all pages?
BTW: the code snippet is actually some a short php if function + an OpenX Javascript Tag
From this search:
Go to /admin/cms_block/ and add a block. Remember the identifier.
In your code add <?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('identifier')->toHtml() ?>
There you go…
For javascript to be included on every page have a look at page.xml layout <default> section. For PHP code see which blocks are included on the page and create a block after (or before) one of them