Use HTML in Attributes

Overview

In this example we create some HTML code, which will open a URL in a new window, as a Layer’s attribute value.

Normally we would select the Link field in Studio and check the checkbox to generate a hyperlink for the field. Studio currently doesn’t support the creation of a hyperlink for a new tab/window directly but it does provide an opportunity to see how html can be stored in a layer’s field.

The following steps presume that you're using a table in PostgreSQL but this can work for other sources such as a Shape file or MapInfo tab file.

  • Open PgAdmin, and use the SQL dialogue to create a column in your table.

  • Populate the column with some HTML that includes the link with the target parameter.

  • Alter the SQL in the MapServer .map file to include the myhtml column as myhtml_raw - this will ensure that the HTML is passed through without alteration.

LAYER   NAME "mylayer"   STATUS OFF   TYPE POINT   INCLUDE "datashare.inc"   DATA "wkb_geometry from (select *, myhtml as myhtml_raw from public.mytable) as foo using unique ogc_fid using srid=27700"   TOLERANCE PIXELS   CLASS     NAME ""     STYLE       SYMBOL "circle"       SIZE 14     END   END  END
  • In Studio include myhtml_raw to in the list of columns displayed. 

Make sure you include the http:// in the myhtml column - failing to so will result in the browser attempting to load the page as a local resource.

Â