Block only visible to teachers (and higher roles)

Block only visible to teachers (and higher roles)

di Mike Wilson -
Numero di risposte: 2

I'm writing a block that I only want displayed to Teachers (and high roles).

I'm struggling to find a solution. Any suggestions?

Thanks,

Mike

Media dei voti:  -
In riposta a Mike Wilson

Re: Block only visible to teachers (and higher roles)

di Davo Smith -
Immagine Core developers Immagine Particularly helpful Moodlers Immagine Peer reviewers Immagine Plugin developers
This is a quick reply off the top of my head, with a reference this page: http://docs.moodle.org/en/Development:Blocks
but what you probably want to do is:

1. define a capability for viewing your block
('block/blockname:view') & set the default to be true for teachers (have a look at an example in any plugin - look for db/access.php ).
2. Set the title to null and the content to null, when the user does not have that capability
(this should stop it displaying).

I may have got that a bit wrong, but hopefully that gives you a direction to start in.

EDIT: See also here: http://docs.moodle.org/en/Development:Blocks/Appendix_A#get_content.28.29
In riposta a Davo Smith

Re: Block only visible to teachers (and higher roles)

di Mike Wilson -

Made loads more sense once I'd had a look at the db/access.php file and how it links to the capabilities.

Cheers for your help. Much appreciated.