HTML Links

This shows how to make an html link in a PG problem.

Complete Code

Download file: HtmlLinks.pg

POD for Macro Files

PG problem file

Explanation

DOCUMENT();
loadMacros(
    'PGstandard.pl',            'PGML.pl',
    'parserNumberWithUnits.pl', 'PGcourse.pl'
);

Preamble

An example below uses units, so the parserNumberWithUnits.pl is loaded.

$ans = NumberWithUnits('4', 'ft');

Setup

This perl code sets up the problem.
BEGIN_PGML
The answer to all questions is on
[@ htmlLink('http://www.google.com/', 'this page') @]*.

A link to a
[@ htmlLink(alias('local.html'), 'local file', 'TARGET="_blank"') @]*.

It helps to [@htmlLink(
    "${htmlURL}plotter.html",
    'sketch the graph',
    'TARGET="plotter"'
)@]*.

Enter 4 feet: [__]{$ans}

Don't forget to enter [@ helpLink('units') @]*.
END_PGML

ENDDOCUMENT();

Statement

The htmlLink function is used to insert links in the first three examples. The page to load is given is the first argument to htmlLink, and the text to display for the link is the second argument.

The first example is a link to a general URL.

The second example shows how to link to a page that is in the same directory on the WeBWorK server as the PG file. The alias function creates the correct link to this file. Setting the target to be _blank will open a new (blank) window or tab.

The third example shows how to link to a page that is under the html subdirectory of a course’s main directory. In this example, plotter.html is a file that has been placed in the course’s html directory. The course’s html directory can be linked using ${htmlURL} as in the example given or by using alias("${htmlDirectory}plotter.html"). Note that this will not work unless this problem is used in a course and a plotter.html file placed into the course’s html directory.

The fourth example uses the helpLink method defined in PGbasicmacros.pl. The following is a list of all help topics: angle, decimal, equation, exponent, formula, fraction, inequality, limit, log, matrix, number, point, vector, interval, unit, and syntax.