General developer forum

html_writer::tag escaping moodle url

Picture of Julian Jan.
html_writer::tag escaping moodle url


I have a little problem with html_writer::tag:

When i use the following 2 lines:

$target_1 = new moodle_url('/mod/multiplesurvey/view.php',array('edit'=>'true','id'=>3));
$html .= html_writer::tag('input','',array('type'=>'button','value'=>'Test Survey','onclick'=>'location.href="'.$target_1.'"'));

it always sends me to http://localhost/moodle/mod/multiplesurvey/view.php?edit=true&id=3

so it always escapes the & before the second parameter !

what do i do wrong or is this the wrong funktion in the renderer.php file ?


Average of ratings: -
Tim at Lone Pine Koala Sanctuary
Re: html_writer::tag escaping moodle url
Core developersDocumentation writersParticularly helpful MoodlersPlugin developers

Acutally, your problem is with moodle_url. If you don't want escaping, you have to use $url->out(false);

$url->__toString(); (which is what your string concatenation will call) does $url->out(true);

Average of ratings: -
Re: html_writer::tag escaping moodle url

Can html_writer assist in outputing information in a new window?

Hor example, can you add a _blank?



Average of ratings: -
Re: html_writer::tag escaping moodle url
Core developersParticularly helpful MoodlersPlugin developers

You really should be posting new questions as new discussions, rather than replying to an only vaguely related old question.

Anyway, the answer is:

html_writer::link($url, 'Some text to display', array('target' => '_blank'));

(but please don't do it, it often annoys end users)

Average of ratings: Useful (1)