Block only visible to teachers (and higher roles)

Block only visible to teachers (and higher roles)

by Mike Wilson -
Number of replies: 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

Average of ratings: -
In reply to Mike Wilson

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

by Davo Smith -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of 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 reply to Davo Smith

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

by 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.