Magento - Using same template on mutiple blocks causing error - list

I have 3 jQuery tabs and want to fill each tab with products from different categories. The tabs are displayed on a category page. In the category page "custom layout update" I have this:
<block type="catalog/product_list" category_id="38" limit="6" name="tabs_new" template="catalog/product/tab_list.phtml" />
<block type="catalog/product_list" category_id="39" limit="6" name="tabs_topsellers" template="catalog/product/tab_list.phtml" />
<block type="catalog/product_list" category_id="40" limit="6" name="tabs_sale" template="catalog/product/tab_list.phtml" />
tab_list.phtml is just a copy of list.phtml with the toolbars stripped out and some markup changes.
In my category view.phtml file I have the following:
<div id="tabs-1">
<?php echo $this->getChildHtml('tabs_topsellers') ?>
</div>
<div id="tabs-2">
<?php echo $this->getChildHtml('tabs_new') ?>
</div>
<div id="tabs-3">
<?php echo $this->getChildHtml('tabs_sale') ?>
</div>
But when I go to the page, I get this error:
Mage registry key "isList" already exists
Any ideas how I can do this?

For fast fix you can use Mage::unregister('isList'); before echo each block

2 solutions :
before registering a value, check if it exists already with :
if (!Mage::registry('isList')) {
Mage::register('isList');
}
use the third parameter "$graceful" of the Mage::register() function in order to ignore the registering of an existing variable (it doesn't throw an exception and do just nothing)

Awesome I had a similar issue with Ultimo theme.
exception 'Mage_Core_Exception' with message 'Mage registry key "isList" already exists' in /home/devlovethe/public_html/app/Mage.php:595
I was trying to use product_list_featured for multiple categories.
{{block type="ultimo/product_list_featured" template="catalog/product/list_featured_slider.phtml" category_id="97" product_count="12" breakpoints="[0, 1], [320, 2], [480, 3], [768, 4], [960, 5], [1280, 6]" pagination="1" centered="1" hide_button="1" block_name="Our Featured Products"}}
At the end of list_featured_slider.phtml I added
<?php Mage::unregister('isList'); ?>

Related

ACF field content not retrieving in Wordpress Multisite

I am using ACF repeater field in Wordpress Multisite template. Fields showing in its admin panel and I can add content using back end. But those data not showing in front end. This is my code to retrieve data.
<?php if(get_field('history')): ?>
<?php while(has_sub_field('history')): ?>
<div class="col-lg-3 history">
<h3><?php the_sub_field('year'); ?></h3>
<div class="description"><p><?php the_sub_field('description'); ?></p></div>
</div>
<?php endwhile; ?>
I have 3 sites.
/xx
/xx
/xx
How can I show data in front end..?
I believe your if statement is incorrect. its should probably ready if(get_sub_field('history')):

Move "Submitted By" from node.tpl to page.tpl

I'm looking to move "Submitted By" info from node.tpl to page.tpl however when I add the following from node.tpl I get errors. Im assuming I dont have access to those variables, but would like to know how I can set up a pre-proccess to get it to display as it does in the node.tpl
<?php if ($display_submitted): ?>
<div class="submitted">
<?php print $submitted; ?>
</div>
<?php endif; ?>
You can either use a preprocess function in the template.php of your theme, as explained here:
https://drupal.stackexchange.com/questions/40222/how-can-i-print-node-authors-last-login-date-on-page-tpl-php
In your case it would look like this (tested on Drupal 7):
function yourtheme_preprocess_page(&$variables) {
$variables['author'] = "";
if (isset($variables['node']) && ($account = user_load($variables['node']->uid))) {
$variables['author'] = $account->name;
}
}
And then in your page.tpl.php use this:
Submitted by: <?php print $author; ?>
If you don’t want to touch any of your theme’s files, but you need to output the author’s name in another region as the node content, you could create a view (block display) containing the node author, and assign it to the region.
While normally done in node.tpl.php, if the page is a node view page, the $node variable is also available in page.tpl.php
You can then use something like:
if (isset($node)) {
// Check if display submitted variable is set for this node type
if (variable_get('node_submitted_'. $node->type, 0)) {
// Do stuff
}
}
An alternative approach would be adding the required logic instead to an implementation of
hook_preprocess_page
Bonus update: You can see the $node variable added to page.tpl.php in core template_preprocess_page
if ($node = menu_get_object()) {
$variables['node'] = $node;
}
In page.tpl.php:
<div class="submitted">
<?php echo format_date($node->created, 'custom','d.m.Y'); ?><br />
<?php echo 'by ' . $node->name; ?>
</div>

What is the proper way to add a custom dashboard "box" in the Magento backend without editing default templates?

I am working on creating what I hope one day will be a publicly available Magento extension (this part I mention because it's important to me that I do the "right thing" here). One of the things I would like to do is add a box in the default Magento dashboard, basically a new "box" exactly like "Top 5 Search Terms" except with my own content. I would like my new custom box to be the last box that is displayed (ideally).
The issue that I'm running into is that the template that is responsible for rendering the dashboard calls out specific blocks to be rendered, and these blocks are nested inside of html. In other words, where often there is an area where child blocks will be rendered into a nice reasonable HTML element, in this situation it appears that specific blocks are rendered. Here is the contents of /app/design/adminhtml/default/default/template/dashboard/index.phtml
<div class="dashboard-container">
<?php echo $this->getChildHtml('store_switcher') ?>
<table cellspacing="25" width="100%">
<tr>
<td><?php echo $this->getChildHtml('sales') ?>
<div class="entry-edit">
<div class="entry-edit-head"><h4><?php echo $this->__('Last 5 Orders') ?></h4></div>
<fieldset class="np"><?php echo $this->getChildHtml('lastOrders'); ?></fieldset>
</div>
<div class="entry-edit">
<div class="entry-edit-head"><h4><?php echo $this->__('Last 5 Search Terms') ?></h4></div>
<fieldset class="np"><?php echo $this->getChildHtml('lastSearches'); ?></fieldset>
</div>
<div class="entry-edit">
<div class="entry-edit-head"><h4><?php echo $this->__('Top 5 Search Terms') ?></h4></div>
<fieldset class="np"><?php echo $this->getChildHtml('topSearches'); ?></fieldset>
</div>
</td>
<td>
<div class="entry-edit" style="border:1px solid #ccc;">
<?php echo $this->getChildHtml('diagrams') ?>
<?php if (is_array($this->getChild('diagrams')->getTabsIds())) : ?>
<div id="diagram_tab_content"></div>
<?php endif; ?>
<div style="margin:20px;">
<?php echo $this->getChildHtml('totals') ?>
</div>
<div style="margin:20px;">
<?php echo $this->getChildHtml('grids') ?>
<div id="grid_tab_content"></div>
</div>
</div>
</td>
</tr>
</table>
</div>
If I was doing this in my own store, I believe I could achieve this relatively easily by editing the base Magento dashboard template index.phtml above, add what I need to have my block render, something like:
<div class="entry-edit">
<div class="entry-edit-head">
<h4><?php echo $this->__('Top 5 Search Terms') ?></h4></div>
<fieldset class="np"><?php echo $this->getChildHtml('myDashboardBox'); ?></fieldset>
</div>
</div>
But, this isn't my own store, so this doesn't really seem like an option.
Now, after some thought my options seem to be as follows (note that most of these seem "bad" and not something I'd be super proud to have seen in the public):
0) Something obvious that I'm not seeing that you will tell me is the perfect/right solution
1) I might (maybe?) be able to add my custom block inside of one of these other blocks in this area ("topSearches", "sales", etc) and have my block rendered. This does not seem very "clean"
2) I might be able to have the block rendered somewhere else on the dashboard page, and then move it with javascript to the correct place. This would be fairly easy I'm guessing, but feels very "hacky" for obvious reasons.
Does anybody have any feedback on the way to do this, or IF there is a way? Keep in mind that again I would like to release this module publicly so my goal is to do a good job and do as little "hacking" as possible.
Thank you very much for reading!
There is no really clean option, as you said, the template is coded in a non-extendable way, so there will always be some degree of hackiness. This is my personal preferred way of doing it by using event observers. This way it at least doesn't conflict with other modules.
First, add an observer for the core_block_abstract_prepare_layout_after and core_block_abstract_to_html_after event.
<adminhtml>
<events>
<core_block_abstract_prepare_layout_after>
<observers>
<your_module>
<class>your_module/observer</class>
<method>coreBlockAbstractPrepareLayoutAfter</method>
</your_module>
</observers>
</core_block_abstract_prepare_layout_after>
<core_block_abstract_to_html_after>
<observers>
<your_module>
<class>your_module/observer</class>
<method>coreBlockAbstractToHtmlAfter</method>
</your_module>
</observers>
</core_block_abstract_to_html_after>
</events>
</adminhtml>
These two events are dispatched for every block that is instantiated and rendered in Mage_Core_Block_Abstract. In my experience it's not such an issue using them in the adminhtml interface, but on the frontend observers for these events add too much overhead.
Back to the task at hand, you need to create the observer class.
class Your_Module_Model_Observer
{
public function coreBlockAbstractPrepareLayoutAfter(Varien_Event_Observer $observer)
{
if (Mage::app()->getFrontController()->getAction()->getFullActionName() === 'adminhtml_dashboard_index')
{
$block = $observer->getBlock();
if ($block->getNameInLayout() === 'dashboard')
{
$block->getChild('topSearches')->setUseAsDashboardHook(true);
}
}
}
public function coreBlockAbstractToHtmlAfter(Varien_Event_Observer $observer)
{
if (Mage::app()->getFrontController()->getAction()->getFullActionName() === 'adminhtml_dashboard_index')
{
if ($observer->getBlock()->getUseAsDashboardHook())
{
$html = $observer->getTransport()->getHtml();
$myBlock = $observer->getBlock()->getLayout()
->createBlock('you_module/block')
->setTheValuesAndTemplateYouNeed('HA!');
$html .= $myBlock->toHtml();
$observer->getTransport()->setHtml($html);
}
}
}
}
Your template will need to accomodate for the fact that you are inserting a sibling <div> from inside the sibling, but otherwise you should be fine.
</fieldset></div>
<div class="entry-edit">
<div class="entry-edit-head"><h4>Your Module</h4></div>
<fieldset class="np">Your Content
Leave it at that, because the parent template will be closing the <fieldset> and the <div> for you (ugly as heck, I know).

Add Date and Author to node.tpl.php

In the code below I'd like to show the created date, author and have them be linked but nothing for they do not show. I believe I need to be doing $node-> rather that row, haven't figured out the exact code. Or what if anything I need to change under Views in my Drupal 6 installation. Thanks in advance!
<?php if($node->type == 'blog'): ?>
<div class="blog-page">
<div class="title-post">
<div class="top-image">
<?php print $node->field_image[0]['view'] ?>
</div><!--TOP-IMAGE-->
<p>Posted on ?php $row['created'] ?>, by
<?php print $row['name'] ?></p>
</div>
<div class="content-page">
<?php print $node->content['body']['#value'] ?>
</div>
</div>
<?php else: ?>
<?php print $content ?>
<?php endif ?>
Drupal has a node object with tons of related information in it. Basically if you ever need to use information from it like author, date, title, etc, you can easily determine the code by printing the node object.
echo '<pre>';
print_r($node);
echo '</pre>';
lets say it outputted something like this for simplicity's sake:
stdClass {
nid = 3
content = stdClass {
raw = " ... "
clean = " ... "
}
}
To output those bits of information in your template, you'd write in the following way.
for a field with no subclass:
<?php print $node->nid ?>
for a field with a subclass:
<?php print $node->content['raw'] ?>
Does that make sense? after you get that down, you literally can figure out anything when programming drupal templates.
so, if you wanted to construct a url, you'd just chain it up:
<?php
$nid = $node->nid;
$uri = "some/path".$nid;
print $uri;
?>

Customizing joomla template (category, single, etc.)

It's possible to customize the template for different types of content... for example, on homepage: 1 column, on category listing: 2 columns, on single article: 3 columns. In Wordpress it's quite easy, modifying home.php, category.php, single.php.
With what conditionals I can accomplish this in Joomla 1.5?
Thanks
You can conditionally display modules on a page by page basis (based on menu item). You can also assign completely different templates to each page. Furthermore, you can do things like
$option = JRequest::getCmd('option');
$view = JRequest::getCmd('view');
within your index.php and change the page based on the view/component.
Joomla's templating is excellent, with a lot of flexibility.
If only one column contains the real content (componenent/article) you could also work with collapsible module positions. Like this:
<?php if($this->countModules('left')) : ?>
<div class="left_column">
<jdoc:include type="modules" name="left" style="xhtml" />
</div>
<?php endif; ?></code></pre>
Then the presence or absence of modules in this column will determine the layout.