Moodle 2.5 Do I need to use a renderer?

Moodle 2.5 Do I need to use a renderer?

Alicia Wallace發表於
Number of replies: 10

Hi, 

I'm using the sky-high theme as a template and looking at the Frontpage categories list.

What I want to do is change the display of this list so it appears as a set of buttons (image attached).

Most of this can be done through CSS. My only problem is choosing the correct image.

By default the HTML output contains: <div class="category notloaded with_children collapsed" data-categoryid="90" data-depth="1">

Can I use that data-categoryid value in CSS? Something like:

div .category { background: url([[pix:theme|<?php $data-categoryid />]]);} 

I've tried experimenting with the "elegant" technique described in this tutorial here (to make sure the .htaccess instruction doesn't cause problems I've put the new files in a subfolder) and although I can see the css/php file has been attached, none of its rules (for testing purposes I've not tried any php ones yet, I've stuck with basic border colour instructions) are being applied.

Is this possible in Moodle, or do I need to use a renderer? If I need to use a renderer, can someone point me to a more comprehensive tutorial than this because although I can see how that works, I can't see how to make the jump from that to figuring this out.

Thanks in advance

Alicia

附件 categorylist.png
評比平均分數: -
In reply to Alicia Wallace

Re: Moodle 2.5 Do I need to use a renderer?

Richard Oelmann發表於
Core developers的相片 Plugin developers的相片 Testers的相片

If you want to use images as links, is there any reason why you can't just create the images as links in the html section0 on the front page? I would have thought this would be a much more straightforward route than creating renderers to do this, although that certainly would be possible.

In reply to Richard Oelmann

Re: Moodle 2.5 Do I need to use a renderer?

Alicia Wallace發表於

If I've misunderstood - sorry! But I think you're suggesting I just write a static menu on the front page?

I actually want to get rid of the text only list of categories on the front page and replace it with a set of buttons that can dynamically respond to changes in the category list. So, right now on my dev server I have 8 categories displaying on the front page. When this gets pushed to the live server, I expect the category list on the front page will be different. I want the menu to automatically update to reflect the new list of categories displayed on the front page. If the script can't find an image for that category ID, it displays the default list appearance. If it can find the image, it displays the "button" appearance.

Although it is more complicated to set up initially, in the long term it will save huge amounts of time and can be kept updated by anyone who knows where to save the images and how to move the categories around in Moodle.

In reply to Alicia Wallace

Re: Moodle 2.5 Do I need to use a renderer?

Mary Evans發表於

You should have said that at the start!

In reply to Mary Evans

Re: Moodle 2.5 Do I need to use a renderer?

Alicia Wallace發表於

My trouble is I focus on trying to explain what I need to do and forget that sometimes other people need to  know the "why" :/

Sorry! 

In reply to Alicia Wallace

Re: Moodle 2.5 Do I need to use a renderer?

Mary Evans發表於

Hi Alicia,

Depending on your knowledge of PHP you could try creating a renderer, however I would be more inclined to do as Richard suggest and add a table to your Frontpage Site Topic area where you can add your images, and link them to their respective categories, using the built in HTML editor.

You can find a tutorial which explains how to override a renderer HERE.

Cheers

Mary

In reply to Mary Evans

Re: Moodle 2.5 Do I need to use a renderer?

Alicia Wallace發表於

Thanks Mary - I've replied to Richard in more detail, but in summary: I already have an html block on the live server, with a table of images linking to categories and it's not practical or efficient for long term use. I want to get rid of that and replace it with something more responsive.

Thanks for the tutorial link, but I have worked through that and although I understand it, I don't see how to make the leap from that to altering the core_course_renderer::frontpage_categories_list()

I'm looking through the renderers and I think my problem is that I only want to change a very small part, and I just can't find the relevant part. I'll keep looking.

In reply to Alicia Wallace

Re: Moodle 2.5 Do I need to use a renderer?

Mary Evans發表於

I'll have a look at the renderer and see if I can find the part you need.

Cheers

Mary

In reply to Alicia Wallace

Re: Moodle 2.5 Do I need to use a renderer?

Mary Evans發表於
In reply to Mary Evans

Re: Moodle 2.5 Do I need to use a renderer?

Alicia Wallace發表於

Sorted 微笑 I did need a renderer, and once I realised (it took an embarrassingly long time) that of course I couldn't just extend core_renderer, I also needed core_course_renderer it took minutes to work out how to do it.

Thanks for your help, and hopefully I can use "end of school year" as an excuse for my slowness! 微笑

Alicia