Hello readers, so we are back again with a new blog on Moodle. In my previous blog as I promised to come up with the new blog for Creating a block plugin in Moodle, so here I am.
Block is one of a type of plugin in Moodle. It is the most common type of plugin build by Moodle plugin developers. You can add the plugin to frontage page or at any context level. It is one of the simplest plugins you can start with.
We will create a basic block which will display some content on the screen. This blog will give you an idea of how simple and easy it is to create a block plugin.
Later in the upcoming blog, we will look at some advance feature of block plugin creation: Creating Advance Block Plugin in Moodle.
I will be creating a feedback block plugin. The name of the plugin will be ig_feedback. I will use Netbeans 8.1, you can use any editor that you are comfortable with.
To create a basic block plugin we just need 4 files.
We will look into all the supporting files which are required in block plugin.
First, create a folder under moodle/blocks/ig_feedback/ all the files will go under it.
- block_ig_feedback .php: It defines the class definition of the block, it is also responsible for rendering the block on the screen. Below code shows the class creation.
The first line is the definition of our class. The name ig_feedback is replaceable, rest is standard and remains same. It has a init() function which is used to initialize the class variables. In that, we have set the title of our block plugin which will appear in the header of our block.
The get_content function block will display a link which will redirect you to the index.php page. The index.php can be a form page or can have any static content as per your requirement.
- db/access.php: It holds the capabilities of our block plugin. We will add myaddinstance and addinstance capability.
- lang/en/block_ig_feedback.php: This is the language file of our block. The “en” stands for English. If you are creating or supporting other languages, their respective file will go under their languages directory name under “lang” folder. Also, the capabilities which we have declared above need description on the settings page, we need to provide that on this page.
- version.php: This file contains the version details of the plugin along with some advance details also. It is one of the essential files in all the plugin type of Moodle. Below code show how basic version files look like.
So we are done with our Basic Block Plugin.
Now to add the block plugin go to Homepage and click on the gear icon and select Turn editing on option.
Now click on “Add a block”.
From the list select IG “Feedback”.
You will see the above block added to the right side of your Moodle.
Now we will see some configuration related to our block plugin.
Click on the gear icon to the right of the “FEEDBACK” block. See the image below.
Select “Configure Feedback block”
You will see the below screen. Under “Page context” select “Display throughout the entire site” so that your block is accessible from all the pages in Moodle.
And we are done with configuration.
Thank you, all the readers will see you in next blog. Till then keep reading.
Ignatiuz is having a strong expertise to provide better solution for Learning Management System (LMS) Solution as per the client requirements. To know more about the providing- http://ignatiuz.com/solutions/lms-solutions/
If you have any query or want more information on Moodle or Block Plugin, contact us today at +1-484-876-1867 or send us a message.
I absolutely love your blog and find most of your post’s to be exactly I’m
looking for. Would you offer guest writers to write content for yourself?
I wouldn’t mind writing a post or elaborating on some of the subjects you write about here.
Again, awesome site!
wonderful post, very informative. I ponder why the other specialists of this
sector don’t notice this. You should proceed your writing.
I am confident, you’ve a huge readers’ base already!
Hi friends, how is the whole thing, and what you would like to say regarding this article, in my view its in fact
awesome for me.
We are a gaggle of volunteers and opening a new scheme in our community.
Your site offered us with helpful information to work on. You’ve done an impressive task and our entire neighborhood will likely be thankful to you.