Database - Templates - Do not display text in templates if the field is blank
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 that cover the field Year.
Is it possible to do this? Do i need specific programming?
Regards,
Re: Database - Templates - Do not display text in templates if the field is blank
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?
Re: Database - Templates - Do not display text in templates if the field is blank
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:
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!
Re: Database - Templates - Do not display text in templates if the field is blank
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.
Re: Database - Templates - Do not display text in templates if the field is blank
Thanks Al, that's was great.
I don't understand the code completly but i will study for that.
Maybe you can help me with this: https://moodle.org/mod/forum/discuss.php?d=345682
Thanks again.
Re: Database - Templates - Do not display text in templates if the field is blank
Tested. Works very well. Thanks to Mr. Rachels for your great contribution.