How to do proper nesting in a Magento theme? - templates

I've copied the default Magento theme in the two dirs and renamed it.
After a lot of tweaking I've come to a point where I'm stuck.
I've got a 3columns.phtml file where the basic layout resides:
top (top.phtml)
header (header.phtml)
main (main.phtml)
footer (footer.phtml)
with main.phtml:
left.phtml
middle.phtml
right.phtml
Now when I referenced these blocks separately in the 3columns.phtml with the getChildHtml() function everything was peachy. Now, after putting them in the main.phtml file it doesn't seem to work anymore. Any content in the main.phtml is not shown (not even simpel html tags). Thinking it could have to do with the xml layout files I looked into page.xml but found out some things are handled by catalog.xml
I now have these block declarations in page.xml:
top (no template= set)
header (no template= set)
main (template="page/html/main.phtml")
left (template="page/html/left.phtml")
middle (template="page/html/middle.phtml")
topmenu (template="page/html/topmenu.phtml")
breadcrumbs (no template= set)
right (template="page/html/right.phtml")
footer (template="page/html/footer.phtml")
And eventhough top and header have no template set their html shows up fine in the frontend. the footer shows up fine too.
Left's output is shown, but not wrapped by main's output.
Right's output the same.
Middle's output shows, but any getChildHtml calls in it don't.
Any ideas as to what's going on?
Also, how do the page.xml and catalog.xml relate to the template? Does every single call to getChildHtml have to be in the page.xml file? what's the difference between page and catalog.
The part of page.xml: http://www.snipplr.com/view/66919/part-of-pagexml-not-working/
The part of catalog.xml: http://www.snipplr.com/view/66920/default-part-of-catalogxml-not-working/
The 3columns.phtml: http://www.snipplr.com/view/66921/main-theme-file-3columnsphtml/

For the detail explanation you can read Alanstorm's book, "No Frills Magento Layout".
I'll give you "brief" explanation so that you have a little enlightment.
In our controller, when we call $this->loadLayout();, it will automatically "call" <default> handle.
Later, all of the handle in all layout xml will be merged.
Let's say you have <default> in page.xml, then you also have <default> in your catalog.xml.
After the call of $this->loadLayout() those <default> from page.xml and catalog.xml will be merged.
That's the relation between them.
We can say <default> is the main of everything. It is the main structure. Any other layout usually "referencing" from it.
Let's say you want to add something in the main body (content), we will call:
<reference name="content">
<block type="core/template" name="testing" template="some/test/template.phtml"></block>
</reference>
Those tag means: Put <block type="core/template" name="testing" template="some/test/template.phtml"></block> under block with name content.
If you see the definition of block with name content:
<block type="core/text_list" name="content" as="content" translate="label">
<label>Main Content Area</label>
</block>
You can see the type is core/text_list. Block with this type will render every child under it and it DOES NOT need a template.
As you can see, there is no definition for template="blabla/blibli.phtml".
The type of block that have template is core/block_template. In this type of block, if you want to render its child, you have to "consciously" call echo $this->getChildHtml('mykid').
Do you get it?
That's why your definition is incorrect: <block type="core/text_list" name="main" as="main" translate="label" template="page/html/main.phtml">.
core/text_list doesn't need and doesn't have a template. You can imagine if "content" is a core/block_template: every time you're going to create a child under "content" you have to "consciously" call echo $this->getChildHtml('mykid'). Let's say you have 100 child, you will need to call echo $this->getChildHtml('mykid1'), echo $this->getChildHtml('mykid2'), ..., echo $this->getChildHtml('mykid100').
Then let's see your catalog.xml:
<default>
<!-- Mage_Catalog -->
<block type="core/template" name="top" template="page/html/top.phtml"></block>
<block type="core/template" name="header" template="page/html/header.phtml"></block>
<block type="core/template" name="main" template="page/html/main.phtml">
<block type="core/template" name="left" template="page/html/left.phtml"></block>
<block type="core/template" name="middle" template="page/html/middle.phtml"></block>
<block type="core/template" name="right" template="page/html/right.phtml"></block>
</block>
<reference name="footer_links">
<action method="addLink" translate="label title" module="catalog" ifconfig="catalog/seo/site_map">
<label>Site Map</label>
<url helper="catalog/map/getCategoryUrl" />
<title>Site Map</title>
</action>
</reference>
<block type="catalog/product_price_template" name="catalog_product_price_template" />
</default>
I don't get it what you're going to achieve from this catalog.xml. There are no reference for: <block type="core/template" name="top" template="page/html/top.phtml"></block>, <block type="core/template" name="header" template="page/html/header.phtml"></block>, etc.
If you're going to add some layout (children), you need to "referencing" from an existing one. Let's say you're going to add children under block with name "main" and you're going to put the code in your catalog.xml:
Then your catalog.xml will be like this:
<default>
<reference name="main">
<block type="core/template" name="i" template="my/new/template1.phtml"></block>
<block type="core/template" name="dont" template="my/new/template2.phtml"></block>
<block type="core/template" name="know" template="my/new/template3.phtml"></block>
</reference>
</default>
Now it depends on the definition of block with name "main".
If your block with name "main" is:
<block type="core/text_list" name="main" as="main" translate="label">
...
</block>
then those blocks (blocks with name "i", "dont", "know") will be automatically called (rendered).
If your block with name "main" is:
<block type="core/template" name="main" as="main" translate="label" template="page/html/main.phtml">
...
</block>
Then you need to call this in your page/html/main.phtml:
echo $this->getChildHtml('i');
echo $this->getChildHtml('dont');
echo $this->getChildHtml('know');
That's as far as I can explain as it's pretty much incorrect things in your layout, if you get the point, you can fix it by reading my explanation.
Few tips:
To see which handles loaded, put this code in your controller under $this->loadLayout(); :
$layout = Mage::getSingleton('core/layout');
$updates = $layout->getUpdate();
$handles = $updates->getHandles();
var_dump($handles);
To see the generated xml from load layout, put this code in your controller under $this->loadLayout(); :
$layout = Mage::getSingleton('core/layout');
$updates = $layout->getUpdate();
$xml = $updates->asString();
var_dump($xml);
Maybe you will need echo "<pre>" / wrap using htmlentities / Mage::log for neat looking purpose.

Here are some possible explanations.
Since left, middle, and right are children of 'main' you need to call getChildChildHtml (note the double child).
Since 'main' is a child (nested) inside 3columns it is not considered it's own page type (i.e. 1 column), the better solution seems to edit the 3columns.phtml file to have the blocks that you want.
When calling getChildHtml the parameter passed to it is the name='' attribute in the xml (so for example if the 'right' block needs to be called, then we need to find the name attribute in the xml - in this case it's 'right' and use that for the parameter).
The left, footer etc. blocks are showing because they are already being called in the 3columns.phtml file.
Also double check that the template file to 'main' is in the right location.
I hope these were some helpful pointers

Related

how can I deeplink an app from Google Assistant?

I'm creating a dialogflow agent integrated with Google Assistant.
What I'd like to do is to open an app (my app) when a proper intent is matched. I've seen that actions like Youtube, Spotify etc. are able to do that, for example I can tell the Youtube action "search for cats video" and the Youtube app will open with a list of cats videos.
I tried to use the DeepLink class but I then noticed it's deprecated.
DeepLink class
Is there any way you can suggest me to do this?
Thanks in advance
I think you are looking for App Actions. Here are the steps you need to follow:
Find the right built-in intent. actions.intent.OPEN_APP_FEATURE should be the right one for you.
Create and update actions.xml. It should look like
<?xml version="1.0" encoding="UTF-8"?>
<!-- This is a sample actions.xml -->
<actions>
<action intentName="actions.intent.OPEN_APP_FEATURE">
<!-- Use url from inventory match for deep link fulfillment -->
<fulfillment urlTemplate="{#url}" />
<!-- Define parameters with inventories here -->
<parameter name="feature">
<entity-set-reference entitySetId="featureParamEntitySet" />
</parameter>
</action>
<entity-set entitySetId="featureParamEntitySet">
<!-- Provide a URL per entity -->
<entity url="myapp://deeplink/one" name="featureParam_one" alternateName="#array/featureParam_one_synonyms" />
<entity url="myapp://deeplink/two" name="featureParam_two" alternateName="#array/featureParam_two_synonyms" />
</entity-set>
</actions>

Load xaml file and filter tags and values using c/c++

Is there a way to load a .xaml file data, filter the tags, and check values?
For instance, using the bellow code, how can I get all 'variable' tags and check if is 'String'and check if the value contains come specific keyword (using c/c++)?
Thank you
<Flowchart.Variables>
<Variable x:TypeArguments="x:String" Name="strDebugDt" />
<Variable x:TypeArguments="x:String" Name="strMailFilter" />
<Variable x:TypeArguments="sd:DataTable" Name="dtReportAttachments" />
</Flowchart.Variables>

keeping data during orientation changes by using fragments

I am trying to understand fragments. All the examples I read is about having a main activity and then two sub fragments.
The issue is that my program has only 1 activity. Can I make it a fragment?
Current ui main class
public class MainActivity extends Activity {}
Can I make it
public class MainActivity extends Fragment {}
The program I am trying to create will constantly monitor phone variables and display logs in a textView. I don't want to lose the logs when the user changes the orientation or some other change when the os destroys the ui.
The UI is basically 1 textView that gets filled by a runnable that updates the textView every 5 seconds with the content of a linked list. I don't want to lose the content of the linked list basically.
I checked getLastNonConfigurationInstance() but it seems it's depreciated so I don't want to use that
Any help would be highly appreciated.
Amish
Found answer here:
http://blog.webagesolutions.com/archives/458
So after a lot of searching I found that if you add the following:
android:configChanges="orientation|screenSize"
in the androidManifest.xml, the os will not destroy the activity when switching from portrait mode to landscape mode.
My xml file looks like this:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.axr0284.phonecontrol"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="15" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.axr0284.phonecontrol.MainActivity"
android:label="#string/app_name"
android:configChanges="orientation|screenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Hope this helps somebody,
Amish

overriding adminhtml block template in community pool

Is it possible to override template located here /app/design/adminhtml/default/default/template/ (e.g. /app/design/adminhtml/default/default/template/customer/edit/js.phtml) by creating a new module in community pool?
So the thing is that I don't want to override it by placing the file (or anything) in local pool.
Is it possible to do that by extending of appropriate block class or something like that?
I've created the same file in /app/design/adminhtml/default/my_directory/template/ and extended Mage_Adminhtml_Block_Customer_Edit class in /app/code/community/MyCompany/MyModule/Block/Adminhtml/Customer/Edit.php and don't have an idea of how to solve this.
In your modules' config (app/code/community/MyCompany/MyModule/etc/config.xml) add the following section:
<adminhtml>
<layout>
<updates>
<mycompany_mymodule>
<file>mycompany_mymodule.xml</file>
</mycompany_mymodule>
</updates>
</layout>
</adminhtml>
This will make mage look for a new file in app/design/adminhtml/default/layout/mycompany_mymodule.xml which should look something like this:
<?xml version="1.0"?>
<layout>
<adminhtml_customer_edit>
<reference name="customer.edit.js">
<action method="setTemplate">
<template>mydirectory/edit/js.phtml</template>
</action>
</reference>
</adminhtml_customer_edit>
</layout>
And then work on your file app/design/adminhtml/default/template/mydirectory/edit/js.phtml. There is probably no need to replace/extend the current block because it is already doing a good job as it is.

magento - where to put templates

I am following the Alan Storm Magento tutorials
http://alanstorm.com/layouts_blocks_and_templates
In this tutorial he suggests creating an html template file at this location
app/design/frontend/base/default/template/simple_page.phtml
However templates look like they are grouped into additional directories by module name. Is this the current standard?
I am using Magento 1.6.2. I am not sure what version the tutorial is tested for.
* additional information *
I created a file called "local.xml" at this location
app/design/frontend/base/default/layout/local.xml
that contains:
<layout version="0.1.0">
<default>
<reference name="root">
<block type="page/html" name="root" output="toHtml" template="simple_page.phtml" />
</reference>
</default>
</layout>
then file "simple_page.phtml" in directory:
app/design/frontend/base/default/template/
that contains:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
</head>
<body>
<p>hello world</p>
</body>
</html>
After clearing cache, I get "white screen of death" on home page, however helloworld page works.
If I erase local.xml, front page comes back.
Here is a short Turorial but the main concept is that you make your own theme/template and overwrite the default templates.
So you can create under System -> configuration -> Design under the point Theme you change the default to your own theme name like "my_theme".
Rest you can see in the tutorial. You can put a folder with your theme name to
app\code\frontend\default\my_theme
Then you can copy the template from default with the same folder structure to your theme and magento take the template from your theme folder instead the default template.
Keep reading the tutorial...
http://alanstorm.com/layouts_blocks_and_templates
"If you go to any other page in your Magento site, you’ll notice
they’re either blank white, or have the same red background that your
hello world page does. Let’s change your local.xml file so it only
applies to the hello world page. We’ll do this by changing default to
use the full action name handle (helloworldindexindex)."
<layout version="0.1.0">
<helloworld_index_index>
<reference name="root">
<block type="page/html" name="root" output="toHtml" template="simple_page.phtml" />
</reference>
</helloworld_index_index>
</layout>