Show Joomla article tags in override of newsflash module - joomla

We would like to create an override for the Joomla newsflash module which should be able to display the individual Joomla article tags on the frontend:
"tag 1, tag 2, tag 3 etc.."
RokSproket from rockettheme.com is able to achieve exactly that output. But we would like to have the same result with the newsflash module. We currently have the following code saved in our new _item.php override. There is no error message on the frontend but also no tags are visible. Any help is much appreciated.
<?php if ($params->get('show_tags', 1) && !empty($item->tags)) : ?>
<?php $item->tagLayout = new JLayoutFile('joomla.content.tags'); ?>
<?php echo $item->tagLayout->render($item->tags->itemTags); ?>
<?php endif; ?>

Here's how we've solved that question:
<?php
$itemtags = (new JHelperTags)->getItemTags('com_content.article', $item->id);
$taglayout = new JLayoutFile('joomla.content.tags');
$tags='';
if( !empty($itemtags) )
$tags = '<div class="itemtags">'.str_replace(',','',$taglayout->render($itemtags)).'</div>';
?>
<?php echo $tags; ?>

Related

Magento - how to filter categories in phtml

I have been working on the maga menu. I got the collection in phtml like:
<?php $_helper = Mage::helper('catalog/category') ?>
<?php $_categories = $_helper->getStoreCategories() ?>
<?php $currentCategory = Mage::registry('current_category') ?>
Now I have to add the filter to show specific categories. Like I have an array(1,2,3,4) of categories that i want to show. so how can I apply filter to this Helper.
Any one have any suggestion please answer.
Thanks.
The first answer is correct but it's not efficient as it consumes unnecessary database round trips. #Karan's code issues a query to the database for every id. Just imagine if the number of category ids to be filtered were 50 or above.
My example would be this:
<?php
$catIds = array(1,2,3,4);
$catCollection = Mage::getModel('catalog/category')->getCollection()->addAttributeToFilter('id', $catIds)->addAttributeToFilter('is_active',1);
foreach($catCollection as $category){
echo $category->getName()." ";
}
This will reduce the database roundtrip to just one.
use this code
<?php $catids[]=array(1,2,3,4);
foreach($catids as $id):
$_category = Mage::getModel('catalog/category')->load($id);
if($_category->getIsActive()):
echo $_category->getName();
endif;
endforeach;
?>
and don't forget to link my answer if it was helpful

Magento - Unable to display custom options

I'm using a module for displaying grouped configurable products and all options are showing except custom options. They are displaying on the configurable product page but that's it. I'm trying to use the code in app\design\frontend\blank\blank\template\catalog\product\view\options.phtml in my custom configurable.phtml but $_options is showing up null. Here is the code used to retrieve $_options
<?php $_options = Mage::helper('core')->decorateArray($this->getOptions()) ?>
<?php if (count($_options)):?>
and after the javascript
<?php foreach($_options as $_option): ?>
<?php echo $this->getOptionHtml($_option) ?>
<?php endforeach; ?>
</dl>
<?php else: echo dlkghflghf;?>
<?php endif; ?>
The dlkghflghf is displaying so i know $_options is not showing up. Any suggestions?
Your custom configurable.phtml is a template of what block? You can use a block that extends Mage_Catalog_Block_Product_View_Options or you can set your own method for options like the method from Mage_Catalog_Block_Product_View_Options, you also need to have a method getProduct():
public function getOptions()
{
return $this->getProduct()->getOptions();
}

Magento: Display Category Image by ID in CMS page

Is there a way to display a category image by it's category id in a CMS page?
You can display a category link by id with:
{{widget type="catalog/category_widget_link" anchor_text="Displayed Text" title="Title attribute text" template="catalog/category/widget/link/link_block.phtml" id_path="category/22"}}
Or display category products by it's id.
{{block type="catalog/product_list" category_id="14" template="catalog/product/list.phtml"}}
But I can't figure out hwo to display a specific categories image in a CMS page just by calling it's id.
Any idea?
In stock magento you cant.
There are essentially 3 ways of achieving this, in order of preference (good to bad imo):
Create and use a widget
Embed directly in cms page and use a custom block type for initialising the category
Embed directly in a cms page, use core/template block type and initialise category inside the template directly
1. Use a widget
I have previously answered a similar question and provided a complete example on how to build such a widget specific to a category:
magento - category name and image in static block?
2. Custom module
You nned to create a module with a block to support this. You can then just include the block in cms pages using the following syntax:
{{block type="yourmodule/category_image" category_id="14" template="yourmodule/category/image.phtml"}}
Your block class is going to look like this:
<?php
class Yourcompany_Yourmodule_Block_Category_Image extends Mage_Core_Block_Template
{
public function getCategory()
{
if (! $this->hasData('category')) {
$category = Mage::getModel('catalog/category')->load($this->getData('category_id'));
$this->setData('category', $category);
}
return $this->getData('category');
}
}
and your template class is going to look like this:
<?php
$_helper = $this->helper('catalog/output');
$_category = $this->getCategory();
$_imgHtml = '';
if ($_imgUrl = $_category->getImageUrl()) {
$_imgHtml = '<p class="category-image"><img src="'.$_imgUrl.'" alt="'.$this->htmlEscape($_category->getName()).'" title="'.$this->htmlEscape($_category->getName()).'" /></p>';
$_imgHtml = $_helper->categoryAttribute($_category, $_imgHtml, 'image');
}
?>
<?php if($_imgUrl): ?>
<?php echo $_imgHtml ?>
<?php endif; ?>
3. Use core/template block type
Include on the cms page like so..
{{block type="core/template" category_id="14" template="category/image.phtml"}}
Create your template - catalog/category/image.phtml
<?php
$_helper = $this->helper('catalog/output');
$category = Mage::getModel('catalog/category')->load($this->getData('category_id'));
$_imgHtml = '';
if ($_imgUrl = $_category->getImageUrl()) {
$_imgHtml = '<p class="category-image"><img src="'.$_imgUrl.'" alt="'.$this->htmlEscape($_category->getName()).'" title="'.$this->htmlEscape($_category->getName()).'" /></p>';
$_imgHtml = $_helper->categoryAttribute($_category, $_imgHtml, 'image');
}
?>
<?php if($_imgUrl): ?>
<?php echo $_imgHtml ?>
<?php endif; ?>
I don't think you'll be able to just call the image because it is not a block. In /design/base/default/template/category/view.phtml, it's just calling the image url as an attribute of the block and then building the output HTML right in the template file. There isn't any specific element in the block that renders it to call with magento's shortcode.
Best best would be to build a new widget. There's plenty of guides, and they're pretty awesome once you get to know them better.

Magento - Filter Category list by category attribute

I have a list of store categories, and everything is working well except for one thing. I would like the list of categories to omit any that are set as 'Include in Navivation Menu = No'.
I can tell at this point that this attribute is not being loaded, but I'm having a difficult time figuring out where to place the filter. Currently, I am getting my category list via:
<?php $_helper = Mage::helper('catalog/category') ?>
<?php $_categories = $_helper->getStoreCategories() ?>
Followed by:
<?php foreach ($_categories as $_category) : ?>
<?php $_category = Mage::getModel('catalog/category')->load($_category->getId()) ?>
...
...
At this point, I have my category objects how I want them. But if I run a debug on these objects, the 'include_in_menu' attribute is not listed.
So for some reason:
<?php $_subCategory->getIncludeInMenu() ?>
Was not working for me after I ran:
<?php foreach($_parentCategory->getChildrenCategories() as $_subCategory) : ?>
The object was still the same model, but ['include_in_menu'] was no longer part of the object. I don't like this solution, but I just reconverted the object back:
<?php $_subCategory = Mage::getModel('catalog/category')->load($_subCategory->getId()) ?>
And then it worked fine. Not sure why getting the children would strip down the object, but it does.

Best way for creating dynamic sidebar section in Symfony 1.4

I have few frontend modules which has own sidebar menu link. I want to create those links in actions class of module:
public function preExecute()
{
$items['plan/new'] = 'Create Plan';
$items['plan/index'] = 'Plans Listing';
$this->getResponse()->setSlot('sidebar', $items);
}
Slot file sidebar.php
#apps/frontend/templates/sidebar.php
<?php slot('sidebar') ?>
<ul>
<?php foreach($items as $url => $title) : ?>
<li><?php echo link_to($url, $title) ?></li>
<?php endforeach ?>
</ul>
<?php end_slot() ?>
layout.php:
<?php if (has_slot('sidebar')): ?>
<div id="sidebar"><?php include_slot('sidebar') ?></div>
<?php endif ?>
but my output is Array, how can I render my slot?
You seem to be mixing slots and partials. In your action, you set your slot to an array, later you call include_slot, and the string representation is Array, that is correct.
You should pass items via $this->items = $items, then in your action see if isset($items) is true, and call include_partial("sidebar", array("items" => $items)) if neccesary. This will look for a file called _sidebar.php.
For more detailed information of how this stuff works, read the Inside the View Layer: Code fragments part of the sf1.4 book.

Resources