Newbie to html_writer - how to add the keyword *download*

Newbie to html_writer - how to add the keyword *download*

by Frankie Kam -
Number of replies: 1
Picture of Plugin developers

Hi There

I used the code

    $output .= html_writer::link($url, 'click me', str_replace('=""','',array('download'=>''))); 

in order to get the result
<a href="the url" download>click me</a>


Is there a simpler way?

What I did was to get this

     <a href="the urldownload="">click me</a>

and then using the str_replace() to replace the ="" with nothing, giving

    <a href="the urldownload>click me</a>

After 30 minutes of searching for a solution, I gave up and used my str_replace() function to brute force what I wanted. Haha. There must be a better and easier way.  Anyone?

Regards
Frankie Kam 


Average of ratings: -
In reply to Frankie Kam

Re: Newbie to html_writer - how to add the keyword *download*

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

In this case it is probably best to given an attribute value, since that will then be used as a suggested filename for the file being saved. E.g.

<a href="the urldownload="suggested-filename.csv">click me</a>