Random glossary entry - possible to limit block height?

Random glossary entry - possible to limit block height?

by Leah Holroyd -
Number of replies: 1

I've just added a Glossary to my Moodle site and added a Random Glossary Entry block to the main page. However, a lot of the definitions of the terms in the Glossary are pretty long - i.e. running to 2, 3 or 4 paragraphs - which means that the blocks are ridiculously big! It just doesn't look right (see screenshot).

What I'd really like is to set it so that the block displays, say, the first 100 characters of the definition and then a [click to read more] link or something along those lines.

Does anyone know if this is possible? Or can anyone suggest a workaround?

Attachment Random_gloss.PNG
Average of ratings: -
In reply to Leah Holroyd

Re: Random glossary entry - possible to limit block height?

by Sheilla Norton -

I had the same issue. I used the block to display FAQs with detailed answers and images. The block was so long it did not fit well on my home page. I'm not sure if you found a solution for this yet, but here is what I did to shorten the definitions of the entries.

  • Add 3 new configurations for the random glossary entry block in the /blocks/glossary_random/edit_form.php. [Use short definitions, # of characters to include, use images yes/no]
  • Added language strings for the configurations in the blocks/glossary_random/lang/en/block_glossary_random.php
  • Added a code to utilize the configurations in the blocks/glossary_random/block_glossary_random.php file.

**I want to premise this with the disclaimer that I am not a programmer. I changed this code in a Moodle 2.9 version (other versions may be different). Use this at your own risk.**

Add in file blocks/glossary_random/lang/en/block_glossary_random.php (at bottom or where it makes sense)

$string['shortdefinition'] = 'Show shortened definition for each entry with no images.'; // Added configuration to shorten the definition
$string['nocharc'] = 'Number of characters to show in shortened definition.';
$string['showimage'] = 'Include images in the shortened definition?'; //END

Add in file /blocks/glossary_random/edit_form.php near line 63 after the config_showconcept entry

// Added configuration to shorten the definition
        $mform->addElement('selectyesno', 'config_shortdefinition', get_string('shortdefinition', 'block_glossary_random'));
        $mform->setDefault('config_shortdefinition', 0);
       
        $mform->addElement('text', 'config_nocharc', get_string('nocharc', 'block_glossary_random'));
        $mform->setDefault('config_nocharc', 200);
        $mform->setType('config_nocharc', PARAM_INT);
       
        $mform->addElement('selectyesno', 'config_showimage', get_string('showimage', 'block_glossary_random'));
        $mform->setDefault('config_showimage', 0);
        //END

Added to /blocks/glossary_random/block_glossary_random.php near line 143 and after

$options = new stdClass();
                $options->trusted = $entry->definitiontrust;
                $options->overflowdiv = true;

//Added configuration to shorten the definition.

if (empty($this->config->shortdefinition)) {
$entry->definitionformat;
} else {
$limit = strpos($entry->definition, ' ', $this->config->nocharc);
$pad = '...<p><a class="btn btn-default btn-small" href="'.$CFG->wwwroot.'/mod/glossary/showentry.php?courseid='.$glossary->course.'&eid='.$entry->id.'&displayformat='.$glossary->displayformat.'">Read More</a></p>';
if (empty($this->config->showimage)) {
$entry->definition = preg_replace("/<img[^>]+\>/i", "", $entry->definition);
} else {
$entry->definition;
}
$entry->definition = substr($entry->definition, 0, $limit);
$entry->definition .= $pad;
}
//END

$entry->definition = file_rewrite_pluginfile_urls($entry->definition, 'pluginfile.php', $glossaryctx->id, 'mod_glossary', 'entry', $entry->id);
                $text .= format_text($entry->definition, $entry->definitionformat, $options);


Hope that helps.

Average of ratings:Useful (1)