## Themes

### Amending print_category_info

Amending print_category_info

Hi,

My theme (hartpury) is based on formfactor, Moodle version 2.4

I want to totally customise print_category_info and (having spent some time butchering moodle/course/lib.php) I know how to make the php work.

However, I need the edits to lib.php to be in my own theme only. As the function already exists in course/lib.php, I copied it to theme/hartpury/lib.php and I also created a renderers.php which only contains: "

<?php

class theme_hartpury_core_renderer extends core_renderer {

}"

As my frontpage now contains only empty head and body tags, that's obviously not entirely correct, but I can't find any guidance on this. Can anyone point me in the right direction?

Thanks

Average of ratings: -
Re: Amending print_category_info

Looks like you are nearly there.

READ THIS and you will learn how to crack the renderer code!

You will also need to add this line in yout hartpury/config.php

$THEME->rendererfactory = 'theme_overridden_renderer_factory'; Cheers Mary Average of ratings: Useful (1) Re: Amending print_category_info You're marvellous, thank you! Average of ratings: - Re: Amending print_category_info Hi again, Sorry, but I'm having a slight problem. If I understand the renderer explanation, I can only overwrite the functions in outputrenderer.php. Is that correct? The bits I know I want to alter are In lib.php function print_whole_category_list($category=NULL, $displaylist=NULL,$parentslist=NULL, $depth=-1,$showcourses = true) {
global $CFG; if ($category) {
if ($category->visible or has_capability('moodle/category:viewhiddencategories', context_system::instance())) { print_category_info($category, $depth,$showcourses); //<-The function is called here
} else {
return; // Don't bother printing children of invisible categories
}
}

/**
* Prints the category info in indented fashion
* This function is only used by print_whole_category_list() above
*/
function print_category_info($category,$depth=0, $showcourses = false) {} //<- I'm basically rewriting this print_whole_category_list is called by a switch case in index.php foreach (explode(',',$frontpagelayout) as $v) { switch ($v) { /// Display the main part of the front page.

case FRONTPAGECATEGORYNAMES:

print_whole_category_list(NULL, NULL, NULL, -1, false);

break;

Now, in my frontpage.php, all of this is contained within main_content(), somehow. I don't see how.

Am I reading this wrong? Which renderer/ function am I trying to overwrite?

I've worked through the demo on the page that Mary pointed me to, and I'm OK with that, but I can't seem to replicate it with functions outside outputrenderers.php

Average of ratings: -
Re: Amending print_category_info

You can only use renderers to override the output of parts of Moodle that use renderers to generate the output.

Of course, all parts of Moodle should user renderers, but sadly that is not true yet. There is a lot more work to do.

So, basically, you are out of luck. Sorry.

Average of ratings: -
Re: Amending print_category_info

What exactly are you trying to do?

I've been making some changes to the frontpage via moodle/index.php in MDL-25630

This may help you redesign the frontpage after these changes are implemented which hopefully will be soon.

However, it would be useful to know exactly what you want to do with category_info? You may be able to achive this using CSS, but I need to know how you want it to display, either on the page or when printing.

Cheers

Mary

Average of ratings: -
Re: Amending print_category_info

Currently print_category_info creates a series of nested divs, each item in the list is fully enclosed in its own set of divs.

<div>Cat 1</div>
<div><div>Cat 1.1</div></div>
<div><div><div>Cat 1.1.1</div></div></div>
<div><div>Cat 1.2</div></div>

I want to replace the Div structure with Ul / li, and use CSS 3 to create an expanding menu with transitions (you hover on a category name and instead of loading a new page a drop down menu of sub categories appears). I also want to add an optional image for the items printed. I've done, tested and confirmed that this is all possible and works (caveat - it works with divs built in a ul structure, I didn't actually test what happens when you replace Div with UL, but I see no reason why this wouldn't work)

<div>Cat 1
<div>Cat 1.1
<div>Cat 1.1.1</div>
</div>
<div>Cat 1.2</div>
</div>

Average of ratings: -
Re: Amending print_category_info

Have you seen the Tutorial how to extent the custom menu and add course/category list?

That uses a renderer but not sure if it would do what you want it to do.

I'll take a closer look at it myself.

Cheers

Mary

Average of ratings: -
Re: Amending print_category_info

I've looked at this, but although it helped me understand how things fit together, I don't think I can use it.

- I definitely don't want my category list to be printed as part of the custom menu, so I can't use this renderer

- It doesn't help me figure out which renderer (if any) print_category_info comes under

NB: Have to say, the tutorials on here are briliant, I just seem to utterly fail at finding the right ones

Average of ratings: -
Re: Amending print_category_info

Alice,

I spent a lot of thought on this problem last night, and think there may be a way to do this.

I think it quite possible to adapt the renderer that creates a menu branch for category/courses could be modified to just make a ul/li list as a seperate menu that could be called into the frontpage of your site.

The problem is that I'm not really sure how to do that, well I sort of have an idea but it may mean that the main custommenu may not function after I have hacked the code.

Mary

Average of ratings: -
Re: Amending print_category_info

I did consider something similar before I began looking into the code and saw how the site was structured (saw, but didn't quite understand!). From what I saw, editing the custom menu adds a lot of messiness, and I don't want to make that big an alteration.

If it were practical, I'd rewrite the case in the switch statement (FRONTPAGECATEGORYNAMES in index.php) and point it to my own function in my theme.

I don't want to do that, as every update would break my server (actually, the server would function just fine, wouldn't it, because the original code would still be in place..), but on the other hand it's the most minimal intrusion on the core code I can think of.

I'll wander off and think about that switch case and see if it's a dangerous thing to play with. I'd like to hear your further thoughts about custommenu whether I'm successful or not

Average of ratings: -
Re: Amending print_category_info

Hi Alice

https://moodle.org/mod/forum/discuss.php?d=220810

It all looks promising in Moodle 2.5 if you want to use renderers.

Cheers

Mary

Average of ratings: Useful (1)
Re: Amending print_category_info

Brilliant! Thanks for mentioning that, I'll be waiting for that release!

Average of ratings: -
Re: Amending print_category_info

For what it's worth (although I haven't quite polished it yet - I'll revisit it in June when I see how the renderers work in 2.5) I was trying to acheive roughly this: https://moodledev.hartpury.ac.uk/moodle/

I thought it might be worth mentioning because I initially assumed this must have been done many times before, but when I Googled it, although I saw a lot of questions where people were asking for something similar, there was no specific answer.

(sadly, there is apparently no support to transition-delay the display property, so I can't make it force you to pause over an item before it expands - causes problems with long lists as in ALevels and adding a third level to the menu. However, like I said, I'll be revisiting in June)

Average of ratings: -
Re: Amending print_category_info

Gosh that made my ears hurt! My screen fairly screeched with the javascript in that page! LOL

I dare say you could do that with the expand / collapse method in the front page for those course/category links even if they are divs.

Here is a link to an old discussion where I did some wiered and wonderful stuff back in the old days of Moodle (sept 2010).

This would put you some images in the places you want them.
the rest could be styled with more CSS.

Not as slick as the your accordian style idea but similar.

Here is a clip from a theme I am making...to show the different effects you can get.

Average of ratings: -
Re: Amending print_category_info

hi

Actually, i have  created my own theme and when i use the change theme button on the moodle page, i see

$THEME->rendererfactory = 'theme_overridden_renderer_factory'; comes written on a blank page, then the theme changes. Is this an error and how can i prevent this line from being displayed on page. Also, when i change the theme for other Moodle Themes which came in the package the following line is seen. I have followed the tutorial on overriding a render and the config.php of my theme contains the line$THEME->rendererfactory = 'theme_overridden_renderer_factory'; at the end.

Also this issue came when i changed the web address of moodle from localhost to the ip address of my machine and updated the database.

Please post a solution if someone knows ASAP.

Mahak

Average of ratings: -
Re: Amending print_category_info

If you are trying to do any development (including themes) turn on Debugging and set it to DEVELOPER level so you can see all error messages.

Average of ratings: -
Re: Amending print_category_info

It looks like you may have added that code to one of your layout pages so check those first.

You only need the that code in yout theme's config.php so that bit is OK.

But I would do as Tim suggests and enable Debugging, as it is the ony way you will know if your site is working correctly.

Average of ratings: -