J1.5

Difference between revisions of "Make a Section Menu Item drill into a Category Blog layout"

From Joomla! Documentation

(new tip about creating a blog layout instead a list layout for section list drill down)
 
Line 34: Line 34:
  
 
At this point, the Section List Menu Item should drill down to the blog layout, but you should still be able to use Category List layouts for other Menu Items in the site. Note that you will not be able to use Category List layouts for the Categories in the Section List. But you can use Category List layouts for any other Categories.
 
At this point, the Section List Menu Item should drill down to the blog layout, but you should still be able to use Category List layouts for other Menu Items in the site. Note that you will not be able to use Category List layouts for the Categories in the Section List. But you can use Category List layouts for any other Categories.
 +
 +
===Add a parameter to the View===
 +
 +
You can avoid side effects of the previous method by editing the php code and the parameters of your layout.
 +
 +
Add a parameter in to the file \components\com_content\views\section\tmpl\default.xml
 +
<source lang="xml">
 +
<param name="category_layout" type="list" default="list" label="Category Layout" description="PARAMSCATEGORYLAYOUT">
 +
        <option value="">Default</option>
 +
<option value="blog">Blog Layout</option>
 +
</param>
 +
</source>
 +
 +
Edit the code in \components\com_content\views\section\view.html.php. Look for the code:
 +
<source lang="php">
 +
$category->link = JRoute::_(ContentHelperRoute::getCategoryRoute($category->slug, $category->section).'&layout=default');
 +
</source>
 +
 +
and replace it by:
 +
<source lang="php">
 +
$layout = $params->get('category_layout') ;
 +
if ($layout == ''){
 +
$category->link = JRoute::_(ContentHelperRoute::getCategoryRoute($category->slug, $category->section).'&layout=default');
 +
}else{
 +
$category->link = JRoute::_(ContentHelperRoute::getCategoryRoute($category->slug, $category->section));
 +
}
 +
</source>
 +
 +
Then you will have a new parameter in your menu that give you the choice between default and blog layout for your section list.
 +
  
 
[[Category:Tips and tricks]]
 
[[Category:Tips and tricks]]
 
[[Category:Tips and tricks 1.5]]
 
[[Category:Tips and tricks 1.5]]

Revision as of 20:45, 18 January 2009

The "J1.5" namespace is an archived namespace. This page contains information for a Joomla! version which is no longer supported. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.

Copyedit.png
This Page Needs Your Help

This page is tagged because it NEEDS REVIEW. You can help the Joomla! Documentation Wiki by contributing to it.
More pages that need help similar to this one are here. NOTE-If you feel the need is satistified, please remove this notice.


In Joomla! 1.5, a Section Layout Menu Item creates a list of Categories in the Section. When you drill into a Category, a Category List layout shows. In some situations, it is preferable to have a Category Blog layout show instead of a Category List layout. This article shows you how to use a template override to create a Section Layout that drills into a Category Blog layout.

We will discuss this in two parts. In the first part, we'll see how to do this by overriding the rhuk_milkyway template. This is the easiest solution, but it means that you cannot use the Category List layout anywhere in the site.

In the second part, we'll see how we can create a copy of the rhuk_milkyway template so that we can still use the standard Category List layout on other pages in the site.

Override the rhuk_milkyway Template[edit]

A complete explanation of template overrides is available in the article How to override the output from the Joomla! core. Here are the steps for our example:

  1. Create a folder in <Joomla! home>/templates/rhuk_milkyway/html called "com_content". Create a folder under the new "com_content" folder called "category". So the whole thing will be "<Joomla! home>/templates/rhuk_milkyway/html/com_content/category".
  2. Copy these three files from the folder <Joomla! home>/components/com_content/views/category/tmpl to the new folder created above:
    • blog.php
    • blog_item.php
    • blog_links.php.
  3. Rename these three files, changing the word "blog" to "default", as follows:
    • blog.php → default.php
    • blog_item.php → default_item.php
    • blog_links.php → default_links.php

Now, when you drill down from a Section List, you should see a Category Blog layout instead of a Category List layout. As with the normal Section List, you cannot directly set the parameters for the layout that shows after the drill down. However, the following article explains how you can do this using "hidden" Menu Items: How to control Category List layouts when drilling from a Section Layout. In our case, you would create hidden Category Blog Menu Items to control the parameters for the blogs that show in the drill downs.

Create a Copy of rhuk_milkyway[edit]

As mentioned earlier, there is an important side effect of the template override as done above. We will lose the ability to do Category List layouts anywhere in our site. If you don't need to use this type of layout, then the method above is fine. However, if you do want to use Category List layouts in other places in the site, then we need to use the slightly more complicated method discussed in this part.

One important feature of template overrides is that they only affect Menu Items that use a specific template. This is what makes them so flexible. In this case, we can create a second template that overrides the Category List layout to be a Category Blog layout. Since we still have our original template, Menu Items that use the original template will be unaffected by our override. So we can still use the Category List layout for Menu Items that use the original template.

Here are the steps:

  1. Make a copy of the rhuk_milkyway template as outlined in the following article: Tutorial:Create_a_copy_of_the_MilkyWay_Template. Note that you don't need to follow the last three steps (zipping the files and so on) unless you want to distribute the template to other sites.
  2. Follow the instructions above to do the template override in the newly copied template (for example, "my_template"). If you have created the override files in the original template, delete them to restore the original behaviour for this template.
  3. In the Joomla! back end, navigate to Extensions → Template Manager. You should now see the new template in the list.
  4. Click on the new template. A screen will show that allows you to assign the template to Menu Items.
  5. Under the "Menu Assignment" section, click "Select from List" and select the Section layout that you wish to override.
    Note: If you have Category Blog or Category List Menu Items for the Categories in this Section, you will need to assign the new template to these Menu Items as well. This is because Joomla! will use the Itemid for a List or Blog layout for this Category when drilling down, and the template is determined by the Itemid.

At this point, the Section List Menu Item should drill down to the blog layout, but you should still be able to use Category List layouts for other Menu Items in the site. Note that you will not be able to use Category List layouts for the Categories in the Section List. But you can use Category List layouts for any other Categories.

Add a parameter to the View[edit]

You can avoid side effects of the previous method by editing the php code and the parameters of your layout.

Add a parameter in to the file \components\com_content\views\section\tmpl\default.xml

<param name="category_layout" type="list" default="list" label="Category Layout" description="PARAMSCATEGORYLAYOUT">
        <option value="">Default</option>
	<option value="blog">Blog Layout</option>
</param>

Edit the code in \components\com_content\views\section\view.html.php. Look for the code:

$category->link = JRoute::_(ContentHelperRoute::getCategoryRoute($category->slug, $category->section).'&layout=default');

and replace it by:

$layout = $params->get('category_layout') ;
if ($layout == ''){
	$category->link = JRoute::_(ContentHelperRoute::getCategoryRoute($category->slug, $category->section).'&layout=default');
}else{
	$category->link = JRoute::_(ContentHelperRoute::getCategoryRoute($category->slug, $category->section));
}

Then you will have a new parameter in your menu that give you the choice between default and blog layout for your section list.