在joomla中是否可以将包含变量的代码从一个覆盖复制并粘贴到另一个覆盖?

I want to adapt my tags result page (default_items.php) so that instead of only showing the articles title it also shows the core article introduction as shown on a category blog page (blog.php).

I thought I'd do this using overrides by copying the code that outputs the article introduction (round about line 82)

<?php
   $this->item = &$item;
   echo $this->loadTemplate('item');
?>

into the default_items.php file.

All I get is the following error 500 - Layout default_item not found.

Does anyone know how to do this/what the problem is with my approach? Do I just need to define the variables in the default_items.php?

I'm using Joomla 3.2

If I understand you correctly, you have overridden the tag view ( /components/com_tags/views/tag/tmpl/ ). You are in the default_item.php - file in this override, and from here you are calling

<?php
   $this->item = &$item;
   echo $this->loadTemplate('item');
?>

What Joomla does now is to try to load i file default_item_item.php. Since this file does not exist on the path, (the path includes /components/com_tags/views/tag/tmpl, and your override /templates/yourtemplate/html/com_tags/tag ) a 500-error is thrown.

What you should do is to se what data is loaded in the items. Try

<?php
print_r($this->item); 
?>

This will show whatever data is available in the current view (you could also try print_r($this) to see if there are other interesting variables in the current view object that you would like to use. )

If the data you need ( the introtext? ) is not available in $this->item, then there are a couple of solutions to load more data:

  • Load the data directly in the view. This is quick and dirty, but contradicts the mvc-model.
  • Write a content-plugin and load the data in the onContentPrepare - function. This function is called in /component/com_tags/views/tag/view.html.php

The procedure to load the data is similar in both occations. Tell me if you need more help with it...

regards Jonas