Section Links Block to Show Topic Names Instead of Numbers

Section Links Block to Show Topic Names Instead of Numbers

by chinky g -
Number of replies: 11
Hi! Is there a way to modify the Section Links Block to show the topic titles instead of just numbers? Thanks!
Average of ratings: Useful (2)
In reply to chinky g

Re: Section Links Block to Show Topic Names Instead of Numbers

by craig jefferies -
An awesome idea .... I'm listening
In reply to craig jefferies

Re: Section Links Block to Show Topic Names Instead of Numbers

by Jenny Gray -
I've done this before, but we swapped to using the YUI menu block from contrib rather than hack one of the core blocks.

However, if you don't like that block, you can do what you want by editing blocks/section_links/block_section_links.php. We only use the "topics" course format, so I'm not sure how you'd do this with "weeks", but hopefully this will be helpful for you anyway...

This goes in the get_content() function inside the else if ($course->format == 'topics') part.

First add:

$topictitles = get_records('course_sections','course',$this->instance->pageid,'', 'section,summary');

Then change $text = '<ol class="inline-list">' to $text = '<ol class="list">';

Inside the for loop, change what comes after the $style = ($isvisible) ? '' : ' class="dimmed"';

$displaytitle = trim(strip_tags($topictitles[$i]->summary));

if (!empty($displaytitle)) {
if ($i == $highlight) {
$text .= "<li><a href=\"$link$i\"$style><b>{$displaytitle}</b></a></li>\n";
} else {
$text .= "<li><a href=\"$link$i\"$style>{$displaytitle}</a></li>\n";
}



Average of ratings: Useful (2)
In reply to Jenny Gray

Re: Section Links Block to Show Topic Names Instead of Numbers

by Fadi Chalfoun -
Thank you! This helped me a lot. I was also able to get it to show all the course mods under the name of the section (as seen in the main center container). Although it was a bit confusing for me to figure out how to change the name of the section because I didn't think initially that changing the topic description would change the topic title.

Is there an easy way to get it to show the section links box on the left all the time? I want to act as a navigation bar. Thanks again!
In reply to Jenny Gray

Re: Section Links Block to Show Topic Names Instead of Numbers

by Melissa Benson -
So will this take all of the text that you put in each topic..what if there is a bunch of text in your topic and you don't want all of that in the link in the block.
In reply to Melissa Benson

Re: Section Links Block to Show Topic Names Instead of Numbers

by Jim Ashton -
Here's a quick and dirty that will give you a title list in the sections box. It assumes that somewhere in your section summary text you've got a section title as an h1

e.g. <h1>Unit 1 - the first section</h1>

As long as you follow this, the following should work.

As before, edit block_section_links.php in the /blocks/section_links directory

Add summary to the sql select in the get_content() function.

$sql = "SELECT section, visible, summary
FROM {$CFG->prefix}course_sections
WHERE course = $course->id AND
section < ".($course->numsections+1)."
ORDER BY section";

Below the select comment out line:

$text = '<ol class="inline-list">';

then add line

$text = '<ol class="list">';

Lastly, insert the following code immediately after code line

$style = ($isvisible) ? '' : ' class="dimmed"';

The code to insert is:

$getsummary = $sections[$i]->summary;
$bits1 = explode("</h1>", $getsummary);
$bits2 = $bits1[0];
$bits3 = explode("<h1>", $bits2);
$displaybit = $bits3[1];

// the following is optional extra code to keep each list entry to 30 chars.
// if the lenth is over 30 chars, it displays the first 27 and then three dots...

if (strlen($displaybit) > 30)
{
$displaybit = substr($displaybit,0,27) . "...";
}
In reply to Melissa Benson

Re: Section Links Block to Show Topic Names Instead of Numbers

by Chris Collman -
Picture of Documentation writers
Hi Melisa,
My section block disappeared from my course 1.9.4 and I am seeing how to get it back.

In another course on the same site, I created an html block and then created himl links to the course topics. No code tweaks, and it allowed me to display any name and in any order I wanted.

The link looked something like:
<a href="http://localhost/course/view.php?id=4#section-1"> 1. Definitions</a><br /><a href="http://localhost/course/view.php?id=4#section-2">

I think the sections # are only unique in the context of each course (ie with each id=X).

Hope this helps you and others. Best Chris
In reply to Chris Collman

Re: Section Links Block to Show Topic Names Instead of Numbers

by Penny Mondani -

Thank you, Chris!  I had a request from a client to display something other than "1, 2, 3,..." .  I am SO GLAD you posted this suggestion.  I was dreading the idea of code modification...

The HTML block took 3 minutes to create, it works perfectly, and is more flexible than the code hack (I added "click to go directly to a topic" and "alternatively, you can scroll down").

I love simple solutions!  Thanks again.  Penny

In reply to Jenny Gray

Re: Section Links Block to Show Topic Names Instead of Numbers

by Adriane Cônsolo -

Hi Jenny,

It doesn't work in my Moodle 2.3. The strings changed in this version?

Thanks

Adriane

In reply to Adriane Cônsolo

Re: Section Links Block to Show Topic Names Instead of Numbers

by Judy Hsu -

I'm glad that I found this discussion. Is there a solution for Moodle 2.4.5? thanks!

In reply to Judy Hsu

Re: Section Links Block to Show Topic Names Instead of Numbers

by Susan Mangan -

Create a custom HTML block, type out your "table of contents" and for each item in your list add a hyperlink to each corresponding section (the hyperlink should be #section-1, #section-2, etc.