WeBWorK Problems

Link to local pdf

Re: Link to local pdf

by John Jones -
Number of replies: 3
Since no one had come forward with a good reason not to have links to local pdfs, I made a small change to PGalias earlier today and submitted a pull request which would allow it.

Here is more detail for those who are interested.  There are two reasons I can think of to call alias on a local pdf file
  1. make a link to the pdf
  2. use the pdf as the src for an img tag (like including a .png image)
Use 1 seems to be a valid reason to call alias on a pdf, it did not work before, but would now work with the change.  Note, there are a variety of OPL problems which have had links to external pdfs, and the links almost invariably break over time.  If they had been local links where the pdf file had come with the problem, they would still work.

Use 2 is a wash because it fails no matter what (a tag of <img src="myfile.pdf"> doesn't work).  So I don't think we need PGalias to throw an error in that situation.

John

In reply to John Jones

Re: Link to local pdf

by Sukhjit Singh Sehra -

Hi,

Was there any success in attaching link to local pdf files to .pg file?

I want to upload an assignment in PDF to file manager of the course and release on Webwork Assignment for students. But, when I open it: Webwork throws an error message: 

                                 No display module found for path '/CourseName/assignment_name/1/template/file.pdf/

Here, I am trying to access the file.pdf uploaded in File Manage. Any input will be appreciated. 


In reply to Sukhjit Singh Sehra

Re: Link to local pdf

by Danny Glin -

WeBWorK is not designed to provide direct access to files in the templates directory.

From within a pg file you can use the following to create a link to a pdf file:

\{ htmlLink( alias('file.pdf'), "link to file", "TARGET='_blank'" ) \}

If you are using PGML you would use this instead:

[@ \{ htmlLink( alias('error2.pdf'), "link to file", "TARGET='_blank'" ) @]*

Note that the alias subroutine is hard-coded to only handle certain file formats, so pdfs are okay, but if you try to link to some exotic file format you might get an error.

In reply to Danny Glin

Re: Link to local pdf

by Alex Jordan -

Danny's code works for when `file.pdf` is in the same directory as the pg file, as OP describes.

An alternative that is better in some (not all!) situations, is to put the file in the course's html/ folder. That folder is parallel to templates/, so you navigate up one level in the File Manager to get there.

And then replace `alias('file.pdf')` with:
`alias("${htmlDirectory}file.pdf")`

And if you really want to hard code a link to that file in one specific course's html/ folder, then replace  `alias('file.pdf')` with:
`'https://webwork.myschool.edu/webwork2_course_files/mycourse/file.pdf'`
where `myschool` and `mycourse` are edited appropriately.

To decide what is best, think about the consequences of how the .pg file is coded, and what will happen if it propagates to other courses.