I have installed a new extension having a block_featured_products.phtml file under folder inchoo/featuredproducts . I want to call this file in my index.phtml that is under cms folder.
Here which I tried after google search but not working:
<?php echo $this->getLayout()->createBlock('core/template')->setTemplate('inchoo/featuredproducts/block_featured_products.phtml')->toHtml(); ?>
Where I am doing wrong?
Assuming inchoo/featuredproducts/block_featured_products.phtml exists, are you able to output anything from said file (clear contents and throw in some Lorem Ipsum, for example) when it's called?
Personally, I would recommend using XML (cms.xml, page.xml, or simply local.xml) to define your block and its template, like so:
<?xml version="1.0"?>
<layout version="0.1.0">
<default>
<reference name="content">
<block name="block_featured_products" template="inchoo/featuredproducts/block_featured_products.phtml" type="core/template" />
</reference>
</default>
</layout>
Then, in your template file(s), use getChildHtml to call your block, like this:
<?php echo $this->getChildHtml('block_featured_products'); ?>
Resources:
Understanding Magento Block and Block Type
To Display .phtml file in another .phtml file. you can use:
<?php echo $this->getLayout()->createBlock('core/template')->setTemplate('path after template dir/filename.phtml')->toHtml(); ?>
<?php echo $this->getLayout()->createBlock('featuredproducts/listing')->setTemplate('inchoo/featuredproducts/block_featured_products.phtml')->toHtml(); ?>
Go to the extension etc folder where you find config.xml file and in the config.xml file you find tag understanding the block tag you can write your own block tag or you can use that block tag, normally when creating an extension using block tag we move to block folder and in using slash we use to give file name if i want to access Listing .php then i use /listing that's how its work
1) For calling a core template file in .phtml file
<?php
echo $this->getLayout()->createBlock('core/template')->setTemplate('templateFolder/yourtemplate.phtml')->toHtml();
?>
2) For calling a core template file in CMS page
{{block type="core/template" template="templateFolder/your_template.phtml"}}
Related
I am trying to add a bit of HTML to every page of my theme in the after_body_start section of the page.
I created a template here with the following contents app/design/frontend/custompackage/genesis/template/page/custom/siteCanvasAdjustment.phtml:
<p>Hello World</p>
In my local.xml file located here: app/design/frontend/custompackage/genesis/local.xml, I have added the following line of code:
<layout version="0.1.0">
<default>
<reference name="after_body_start">
<bock type="core/template" name="siteCanvasAdjustment" as="siteCanvasAdjustment" template="page/custom/siteCanvasAdjustment.phtml" output="toHtml" before="-" />
</reference>
</default>
However, "Hello World" is still not rendering on the page. I verified that the theme is successfully installed. Changes that I have made to the head.phtml file and placed in my theme work. Also, changes such as the following in local.xml work fine:
<reference name="head">
<action method="removeItem"><type>skin_js</type><name>js/slideshow.js</name></action>
</reference>
Any idea what I am doing wrong? I am new to Magento and read up on all the tutorials but am clearly missing something.
Your local.xml should be under layout folder not directly under theme folder, also your block has spelling mistake it says bock instead of block.
Hope it helps
N.B Don't forget to clear cache.
Cheers
S
I know a trick to make link to article without template (tmpl=component), but I see that it still links some styles:
index.php?option=com_content&view=article&id=171:uvjeti-plaćanja&catid=19:poliklinika&Itemid=101&tmpl=component
Is it possible to create link to just bare bones data you'd see in content editor for example?
It would be prefferable if nothing else but pure article content is returned. No html, body, head ... tags.
I have ended up creating file raw.php which contains following code:
<?php defined( '_JEXEC' ) or die( 'Restricted access' );?><jdoc:include type="component" />
I have placed this into my template folder and I can just call it with following url:
/?option=com_content&view=article&id=171&catid=19&Itemid=101&tmpl=raw
Analog to that you one can make new.php, place it to folder of current template in use and call it with &tmpl=new argument.
I have a html page in which there is a Link whose address is mentioned in AppSettings tag of web config
<appSettings>
<add key="MyAttribute" value="https://www.google.co.in/" />
</appSettings>
Html Code : [i need to do something like this]
<a href=" <%=ConfigurationManager.AppSettings("MyAttribute")%> " > fbm.wrdsreports.com</a>
Note : Above method does not work.Please be patient i am new to HTML.
Can any one suggest me how to do it.
Hi could you please try below..
fbm.wrdsreports.com
In Web2py I am creating some email templates and want to include the tag with my css file LOAD'ed into the view.
How do I use the LOAD function in the view so that it doesn't use jquery as it is an email and pulls from static, css, base.css.
This is what I have now:
<link href="{{=URL('static', 'css/style.css', scheme='http')}}" rel="stylesheet" type="text/css" />
But with this requires that remote content be loaded and most email applications disable this loading.
I was wanting to do this:
{{=LOAD(url=URL('static', 'css/style.css', scheme='http'),ajax=False)}}
But it is returning this:
<script type="text/javascript"><!--
web2py_component('http://127.0.0.1:8000/iid_app/static/css/web2py.css','c382784163112');
//--></script><div id="c382784163112">loading...</div>
<script type="text/javascript"><!--
web2py_component('http://127.0.0.1:8000/iid_app/static/css/style.css','c3845864949');
//--></script><div id="c3845864949">loading...</div>
Any ideas on how to make this just include the test from the file?
If you want to include the content of a CSS file in the email template, just add the following to the template where you want the CSS included:
{{include '../static/css/styles.css'}}
The {{include}} directive looks for the template to be included relative to the application's "views" folder, so the "../" goes up one level from there in the folder structure, and from that point, you can just specify the path to the file you want to include.
Is it possible to call a .ctp file from a layout which is also a .ctp file?
I have a default layout with the topbar, the footer and of course the variable $content_for_layout in the middle. I would like to dispatch the topbar and the footer into two others different .ctp files and I would like to call them from my layout.
You can use elements.
<?php
echo $this->element('topbar');
echo $content_for_layout;
echo $this->element('footer');
?>
You can use elements or, in CakePHP 2.1, you can check out blocks.