Glossary Template creation

Glossary Template creation

by Tina Rowe -
Number of replies: 2

Hello

I am trying to use the customisable template from the glossary to get a bit of extra functionality.  I want to use the entrylist display type of the glossary, but to include the definition in the entry list.  

so instead of a list of concepts that output as title links that lead to a definition page, like this:

Concept one

Concept two

Concept three

It outputs like this, a link plus text.

Concept one

this is some text about concept one...

Concept two

this is some text about concept two...

Concept three

this is some text about concept three...


I looked at the entrylist template and this seemed to be the bit of code I need to change:

This is the exisiting code for the entry list page:

-------

function glossary_show_entry_entrylist($course, $cm, $glossary, $entry, $mode='', $hook='', $printicons=1, $aliases=true) {

    global $USER, $OUTPUT;


    $return = false;


    echo '<table class="glossarypost entrylist" cellspacing="0">';


    echo '<tr valign="top">';

    echo '<td class="entry">';

    if ($entry) {

        glossary_print_entry_approval($cm, $entry, $mode);


        $anchortagcontents = glossary_print_entry_concept($entry, true);


        $link = new moodle_url('/mod/glossary/showentry.php', array('courseid' => $course->id,

                'eid' => $entry->id, 'displayformat' => 'dictionary'));

        $anchor = html_writer::link($link, $anchortagcontents);


        echo "<div class=\"concept\">$anchor</div> ";

        echo '</td><td align="right" class="entrylowersection">';

        if ($printicons) {

            glossary_print_entry_icons($course, $cm, $glossary, $entry, $mode, $hook,'print');

        }

        if (!empty($entry->rating)) {

            echo '<br />';

            echo '<span class="ratings">';

            $return = glossary_print_entry_ratings($course, $entry);

            echo '</span>';

        }

        echo '<br />';

    } else {

        echo '<div style="text-align:center">';

        print_string('noentry', 'glossary');

        echo '</div>';

    }

    echo '</td></tr>';


    echo "</table>\n";

    return $return;

}


function glossary_print_entry_entrylist($course, $cm, $glossary, $entry, $mode='', $hook='', $printicons=1) {

    //Take out autolinking in definitions un print view

    // TODO use <nolink> tags MDL-15555.

    $entry->definition = '<span class="nolink">'.$entry->definition.'</span>';


    echo html_writer::start_tag('table', array('class' => 'glossarypost entrylist mod-glossary-entrylist'));

    echo html_writer::start_tag('tr');

    echo html_writer::start_tag('td', array('class' => 'entry mod-glossary-entry'));

    echo html_writer::start_tag('div', array('class' => 'mod-glossary-concept'));

    glossary_print_entry_concept($entry);

    echo html_writer::end_tag('div');

    echo html_writer::start_tag('div', array('class' => 'mod-glossary-definition'));

    glossary_print_entry_definition($entry, $glossary, $cm);

    echo html_writer::end_tag('div');

    echo html_writer::start_tag('div', array('class' => 'mod-glossary-lower-section'));

    glossary_print_entry_lower_section($course, $cm, $glossary, $entry, $mode, $hook, false, false);

    echo html_writer::end_tag('div');

    echo html_writer::end_tag('td');

    echo html_writer::end_tag('tr');

    echo html_writer::end_tag('table');

}

------


I added a new variable and called it $furtherinfo = glossary_print_entry_definition($entry, $glossary, $cm);

and added that to just below where the anchor was created: 


-----


<?php


function glossary_show_entry_entrylist($course, $cm, $glossary, $entry, $mode='', $hook='', $printicons=1, $aliases=true) {

    global $USER, $OUTPUT;


    $return = false;


    echo '<table class="glossarypost entrylist" cellspacing="0">';


    echo '<tr valign="top">';

    echo '<td class="entry">';

    if ($entry) {

        glossary_print_entry_approval($cm, $entry, $mode);


        $anchortagcontents = glossary_print_entry_concept($entry, true);


        $link = new moodle_url('/mod/glossary/showentry.php', array('courseid' => $course->id,

                'eid' => $entry->id, 'displayformat' => 'dictionary'));

        $anchor = html_writer::link($link, $anchortagcontents);

        $furtherinfo = glossary_print_entry_definition($entry, $glossary, $cm);
         echo "<div class=\"concept\">$furtherinfo</div>";

        echo "<div class=\"concept\">$anchor</div> ";

        echo '</td><td align="right" class="entrylowersection">';

        if ($printicons) {

            glossary_print_entry_icons($course, $cm, $glossary, $entry, $mode, $hook,'print');

        }

        if (!empty($entry->rating)) {

            echo '<br />';

            echo '<span class="ratings">';

            $return = glossary_print_entry_ratings($course, $entry);

            echo '</span>';

        }

        echo '<br />';

    } else {

        echo '<div style="text-align:center">';

        print_string('noentry', 'glossary');

        echo '</div>';

    }

    echo '</td></tr>';


    echo "</table>\n";

    return $return;

}


function glossary_print_entry_entrylist($course, $cm, $glossary, $entry, $mode='', $hook='', $printicons=1) {

    //Take out autolinking in definitions un print view

    // TODO use <nolink> tags MDL-15555.

    $entry->definition = '<span class="nolink">'.$entry->definition.'</span>';


    echo html_writer::start_tag('table', array('class' => 'glossarypost entrylist mod-glossary-entrylist'));

    echo html_writer::start_tag('tr');

    echo html_writer::start_tag('td', array('class' => 'entry mod-glossary-entry'));

    echo html_writer::start_tag('div', array('class' => 'mod-glossary-concept'));

    glossary_print_entry_concept($entry);

    echo html_writer::end_tag('div');

    echo html_writer::start_tag('div', array('class' => 'mod-glossary-definition'));

    glossary_print_entry_definition($entry, $glossary, $cm);

    echo html_writer::end_tag('div');

    echo html_writer::start_tag('div', array('class' => 'mod-glossary-lower-section'));

    glossary_print_entry_lower_section($course, $cm, $glossary, $entry, $mode, $hook, false, false);

    echo html_writer::end_tag('div');

    echo html_writer::end_tag('td');

    echo html_writer::end_tag('tr');

    echo html_writer::end_tag('table');

}



-----

But for some reason that I do not understand , it is now outputting the definition first and then the title.

Does anybody understand why this might be happening?

Thanks

Tina


Average of ratings: -
In reply to Tina Rowe

Re: Glossary Template creation

by William Lu -
Picture of Particularly helpful Moodlers

Hi Tina,

Sorry, I am not answering your question, just a suggestion:

If you want to change the layout of a Glossary, you can do it in Database easily.

Glossary is just a simple Database template, or a Database preset.