Question Authors' Forum

Answer with php code : can I bypass the mandatory php tags?

 
Picture of benoit darties
Answer with php code : can I bypass the mandatory php tags?
by benoit darties - Tuesday, 3 July 2018, 2:22 AM
 

Hi!

First of all Thank you very much for this amazing plugin!

It's simply an unbelievable tool for students.


I have a concern with questions requiring php code. I've read that the student need to begin his code with a <?php or <? mark, and not close it, to perform a successful test.

Is there a way to change this? Ideally, I'd like that the answer either include both opening and closing mark, or none. I tried some basic modifications on the template, but without success.

Thanks for your reply



Picture of benoit darties
Re: Answer with php code : can I bypass the mandatory php tags?
by benoit darties - Tuesday, 3 July 2018, 3:34 AM
 

I think I finally found  the problem...

There was a confusion due to the mention of an error occurring the template editing box (see screenshot). But everything works when testing



Picture of Richard Lobb
Re: Answer with php code : can I bypass the mandatory php tags?
by Richard Lobb - Thursday, 5 July 2018, 10:18 PM
 

Good to know the problem is solved.

Yes, those syntax errors are confusing, I admit. They are generated by the Ace code editor which is managing the template - the embedded Twig code isn't valid PHP. You can turn off Ace if you wish by customising the question or its prototype. There's a checkbox "Template uses Ace" at the bottom of the Customisation panel.

Screen dump showing Template Uses Ace checkbox

I prefer to have it on by default, myself, because syntax colouring makes it much easier to edit large templates. Also, nearly all my templates are in Python nowadays, regardless of what language the question is asking for, and the double braces are generally valid Python.

For small PHP templates, though, the Ace editor might be more of a hindrance than a help.

Richard