Page 1 of 1
Images in subcategories
Posted: 30 Jun 2018, 17:19
by mentalhacker
Hi,
The category images are displayed only in categories view, so in the case of multiple category levels, only the main categories can have images.
I'd like the category view to have the same or similar layout as the categories view has.
I was trying to modify the category template but that didn't work.
Code: Select all
echo '<div class="pd-subcategory">';
echo '<a href="'. JRoute::_(PhocaDownloadRoute::getCategoryRoute($valueSubCat->id, $valueSubCat->alias))
.'">'. $valueSubCat->title.'</a>';
echo '<small>('.$valueSubCat->numdoc.')</small>';
echo '<div class="ph-img">';
echo '<a href="'. JRoute::_(PhocaDownloadRoute::getCategoryRoute($valueSubCat->id, $valueSubCat->alias)).'">'. '<img src="'.$this->t['cssimgpath'].$value->image.'" alt="'.htmlspecialchars(strip_tags($value->title)).'" />'.'</a>';
echo '</div></div>' . "\n";
Could you please help? What is needed to display the images?
Thanks.
Re: Images in subcategories
Posted: 01 Jul 2018, 12:10
by Jan
Hi, do you get any error? Are all the needed variables loaded from the database?
Jan
Re: Images in subcategories
Posted: 01 Jul 2018, 12:39
by mentalhacker
No, there is no error message. The template is ok, but the image filename is not loaded from the database.
The image container and the hyperlink are there:
Code: Select all
<div class="ph-img">
<a href="/letoeltes/pd-test/category/3-lelkipasztor"><img src="/images/phocadownload/" alt=""></a>
</div>
So the variables are missing, and the image is not rendered for some reason. Maybe it's not enough to modify the template because a necessary function is missing.
Any idea?
Thanks.
Re: Images in subcategories
Posted: 01 Jul 2018, 13:02
by Jan
Hi, yes, then in model of the view the variables must be loaded (in the main item function or separately
)
Jan
Re: Images in subcategories
Posted: 01 Jul 2018, 13:39
by mentalhacker
Could you specify the task a little bit more accurately?
Do you mean this file?
components/com_phocadownload/models/category.php
If yes, what's next?
(Is it possible to copy the necessary code from models/categories.php?)
Re: Images in subcategories
Posted: 05 Jul 2018, 14:06
by Jan
Hi,
If yes, what's next?
we are speaking about programming, this means: coding -> testing -> going to next step -> coding -> testing -> going to next step, so I cannot list here all the steps to program some modifications as this is not possible to say it without coding/testing/next step
Could you specify the task a little bit more accurately?
Joomla! extensions are based on MVC - to see some variable in HTML, you first need to load it from database in the model and then you can format it in the View and its output, so for category view of Phoca Download it means:
view:
components/com_phocadownload/views/category/view.html.php -> asking model for the variable (in some current function or some new function)
model:
components/com_phocadownload/models/category.php ->returning the asked variable to view
view:
components/com_phocadownload/views/category/view.html.php -> managing this variable
view output:
components/com_phocadownload/views/category/tmpl/default_files.php
Unfortunately, I didn't do such customization yes, so the only clue advice for now is to see the categories view/model/output and modify the category view based on the categories view (to get the variable of the image, if it is not loaded in category view, to implement in in output on the place where you need to display it)
Jan
Re: Images in subcategories
Posted: 05 Jul 2018, 23:43
by mentalhacker
Yes, these steps are quite obvious, thanks for mentioning and reminding.
But what I was really interested in is that in which files do I need to look around in order to modify templates and corresponding functions, because I only had some guesses but I was not sure.
And yes, I managed to solve the problem with your help: category/view.html.php and models/category.php were the two missing links. All the necessary codes were there in the files of categories view (main categories), so I just had to implement them in the files of subcategories.
Unfortunately, I made a mistake at first when modifying the category template through an oversight. I didn't realize that in subcategories $value is replaced by $valueSubCat, so the code was effectless.
The corrected code of the modified template that I shared in my first post is this:
Code: Select all
echo '<div class="pd-subcategory">';
echo '<a href="'. JRoute::_(PhocaDownloadRoute::getCategoryRoute($valueSubCat->id, $valueSubCat->alias))
.'">'. $valueSubCat->title.'</a>';
echo '<small> ('.$valueSubCat->numdoc.')</small>';
echo '<div class="ph-img">';
echo '<a href="'. JRoute::_(PhocaDownloadRoute::getCategoryRoute($valueSubCat->id, $valueSubCat->alias)).'">'. '<img src="'.$this->t['cssimgpath'].$valueSubCat->image.'" alt="'.htmlspecialchars(strip_tags($valueSubCat->title)).'" />'.'</a>';
echo '</div></div>' . "\n";
The images are displayed in subcategories now.
Thank you, Jan!
Re: Images in subcategories
Posted: 06 Jul 2018, 15:02
by Jan
Hi, great to hear it.
Jan