How to create a button in a HTML block

How to create a button in a HTML block

by Anila Thomas Varghese -
Number of replies: 5

I would like to add a button to a HTML block, so that when the button is clicked it goes to another page depending on the course id. I am using Moodle 3.3.4+. 

Does anyone has an idea on how to do this?

Thank you 

Anila

Average of ratings: -
In reply to Anila Thomas Varghese

Re: How to create a button in a HTML block

by Justin Hunt -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

Without any sort of plugin, you would go into the html view of your html area and paste code like this:

<a href="/MYCOOLPAGE.HTML" class="btn btn-primary">SOME TEXT</a>

That will become a button linked to /MYCOOLPAGE.HTML 

So you would just change the all caps to make it an address and a button caption that work for you.

Toggle the html view of the editor with this button ...


I just did it here ... this is the button ...


SOME TEXT
Average of ratings: Useful (5)
In reply to Justin Hunt

Re: How to create a button in a HTML block

by Anila Thomas Varghese -

Thank you for replying. That was helpful and I was able to create a button in HTML block.

Now I have a more specific case. The html block has a button that has to be viewed only by the teachers and some other code for unity that has to be viewed only by the students. Is this possible? 

I know there is possibility in changing the permission and we can even use the require_capability function to check the permission based on the context. But all these are applicable to the entire block. 

But in my specific case , the button should be visible to the teachers to define a value particular for the course and the unity code should be accessible for students.

Can anyone help in this case?

Waiting for your reply.

Best Regards

Anila

In reply to Anila Thomas Varghese

Re: How to create a button in a HTML block

by Justin Hunt -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

You can specify different permissions per HTML block.

So you could have a teacher version of the block and a student version of the block.

e.g


In reply to Justin Hunt

Re: How to create a button in a HTML block

by Anila Thomas Varghese -

Thank you for replying.

I have found a solution for my case.

Putting my solution so that it can be helpful for others.

I have a student and teacher version for the same block. A button to enter a value for each course by the teacher and a javascript code for interacting with the students.

For making the button on the block available for the teacher, I have given block/xyz:use  in access.php for the teacher.

For accessing the javascript code for the student, In the php code I check the has_capability function and if it satisfies the button is displayed, else the javascript is displayed through an echo.~

Hope this helps somebody.

Best Regards

Anila

Average of ratings: Useful (1)