2

I want to display the intro image of my categories on the category page.

I have a template override for the category blog.

Because of the layout, I need to place the code outside of the override - in the index.php.

Inside of the blog layout it's possible to load the intro image with following code:

<?php if ($this->category->getParams()->get('image')) : ?>
   <?php echo $this->category->getParams()->get('image'); ?>
<?php endif; ?>

When I put this in the index.php following error appears:

Notice: Undefined property: JDocumentHtml::$category in C:\xampp\htdocs\PATHTOTEMPLATE\index.php on line 101

Fatal error: Call to a member function getParams() on null in C:\xampp\htdocs\PATHTOTEMPLATE\index.php on line 101

Is this even possible to load it like this? Or does it need to be in the category view?

1
  • Maybe fleshing out the details your requirement will get an improved answer
    – BodgeIT
    Nov 22, 2016 at 17:22

2 Answers 2

2

Knowing a tiny bit about the joomla request-reponse lifecycle will help here. Joomla runs in the following order: 1. bootstrap the application 2. router 3. component (including your own layout overrides) 4. modules 5. template

Various objects like the jsession and jinput allow you to get and set variables during the lifecyle so if you just set the html of your image from the category layout override into a jinput variable then you can retrieve it in any module or template php. Note using the RAW filter when retrieving the value is required because otherwise your html will probably get stripped out

This would go in your category layout

JFactory::getApplication()->input->set('category_image_html',$this->category->getParams()->get('image'));

this can be in any module or template php

echo JFactory::getApplication()->input->get('category_image_html', 'default_value_if_you_want_one', 'RAW');
1
  • Without testing this looks like a full answer to the specifity of the question although @Seth Warburn's point about adding this to index.php is highly valid.
    – BodgeIT
    Nov 22, 2016 at 17:21
1

Firstly, the only code that should go into index.php is code that should appear on every page. What you want to do is on the category view, so your code should go in the category view override.

It is possible to get something like that working in index.php, but that would be completely the wrong thing to do, so I'm not going to suggest how you might.

‘I want to display the intro image of my categories on the category page.’

What's the problem? Assign an image to your category and Joomla will display it on the category view. This works out of the box, so I can't understand why you would need to do anything at all.

1
  • I think he is trying to show into-images of child category items oin a category blog view. Not sure that's core.
    – BodgeIT
    Nov 22, 2016 at 17:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.