html_writer::tag escaping moodle url

html_writer::tag escaping moodle url

by Julian Jan. -
Number of replies: 3

Hello, 

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 ?

Thanks.

Average of ratings: -
In reply to Julian Jan.

Re: html_writer::tag escaping moodle url

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin 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);

In reply to Tim Hunt

Re: html_writer::tag escaping moodle url

by Andrew C -

Can html_writer assist in outputing information in a new window?

Hor example, can you add a _blank?

Thanks,

Andrew

In reply to Andrew C

Re: html_writer::tag escaping moodle url

by Davo Smith -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin 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)