Developers' Forum

Adding to Twig Question Variable

Re: Adding to Twig Question Variable

Firstly, I assume you're just doing all this as an experimental way of understand the existing code, right? Because you certainly shouldn't ever alter the moodle base classes, such as questionbase, when developing plugin code.

There are a few other odd things going on in your code, but I'd rather not get lost in detail. Instead, here are some suggestions on how to debug code within Moodle.

1. Read https://docs.moodle.org/34/en/Debugging
2. An important tip inexplicably omitted from the above document is the function call debugging(message) which prints a traceback message to the web output, containing the given message parameter. [But note that debugging needs to be turned on, as explained in the above document.] To see the state of a particular variable at the time, such as the $question variable, use debugging(print_r($question, TRUE)). You can insert debugging calls at multiple points of interest in the code.
3. I find the use of a debugger like XDEBUG invaluable. I use the NetBeans IDE myself, with XDEBUG turned on. This allows me to set a breakpoint in the code, inspect variables, single step, etc, just as through I was debugging code locally.
Hope that helps.

Richard