Database - Templates - Do not display text in templates if the field is blank

Database - Templates - Do not display text in templates if the field is blank

by Gonzalo Gutierrez -
Number of replies: 5
Hello, I'm setting up the database activity visualization templates and I want to do something I do not know if it's possible.

For example, my template looks like this:

Autor (Year) Title.
Source: [Source]

I would like the word "Source:" not to be displayed if nothing was entered in the field. The same for the parentheses egg that cover the field Year.

Is it possible to do this? Do i need specific programming?

Regards,
Average of ratings: -
In reply to Gonzalo Gutierrez

Re: Database - Templates - Do not display text in templates if the field is blank

by AL Rachels -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers

Hi Gonzalo,

Which template, List or Single? Could you attach a database preset of what you have now so we can look and maybe come up with a recommendation? Have you tried anything in the CSS template?

In reply to AL Rachels

Re: Database - Templates - Do not display text in templates if the field is blank

by Gonzalo Gutierrez -

Hi Al,

Thanks for your reply and sorry for the delay.

I didn't try with CSS, neither witgh JS.

I attached the database preset.


I give another example:

When the fields have information i would like to see:

Title: Learning how to use Moodle

Author: Al Rachels

Year: 2016


If the fields Author and Year are in blank i would like to see:

Title: Learning how to use Moodle


And not this:

Title: Learning how to use Moodle

Author:

Year:


Thanks!




In reply to Gonzalo Gutierrez

Re: Database - Templates - Do not display text in templates if the field is blank

by AL Rachels -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers

Hi Gonzalo,

Here you go. Added a few lines of script to the single template. You can see them if you click on the HTML tool button when editing the single view template. There are a number of comments to explain what is going on. You can remove them if you want to.

Average of ratings: Useful (2)
In reply to AL Rachels

Re: Database - Templates - Do not display text in templates if the field is blank

by William Lu -
Picture of Particularly helpful Moodlers

Tested. Works very well. Thanks to Mr. Rachels for your great contribution.