Extension:External Data/Retrieving and displaying data

Once you have retrieved data onto a page, from any source, there are three ways to display it on the page:,   and.

Displaying individual values
If this call retrieved a single value for each variable specified, you can call the following:

As an example, this page contains the following text:

.
 * Germany borders the following countries:
 * Germany has population.
 * Germany has area.
 * Its capital is.

The page gets data from this URL, which contains the following text:

"357,050 km²","Austria,Belgium,Czech Republic,Denmark,France,Luxembourg,Netherlands,Poland,Switzerland",Berlin,"82,411,001"

The page then uses #external_value to display the 'bordered countries' and 'population' values; although it uses the #arraymap function, defined by the Page Forms extension, to apply some transformations to the 'bordered countries' value (you can ignore this detail if you want).

By default, #external_value displays an error message if it is called for a variable that has not been set, or if the specified data source is inaccessible, or the data source does not contain any data; and there is no fallback/default value. You can disable the error message by adding the following to LocalSettings.php:

To prevent any further wiki processing of external data, for example, when it is SVG produced by get_program_data, you can use pair.

Displaying a table of values
The data returned by any of "#get" parser functions can also be a "table" of data (many values per field), instead of just a single "row" (one value per field). In this case, you can display it using one of either the functions #for_external_table or #display_external_table.

#for_external_table
This URL contains information similar to that above, but for a few countries instead of just one. Calling #get_web_data with this URL, with the same format as above, will set the local variables to contain arrays of data, rather than single values. You can then call #for_external_table, which has the following format:

...where "expression" is a string that contains one or more variable names, surrounded by triple brackets. This string is then displayed for each retrieved "row" of data.

For an example, this page contains a call to #get_web_data for the URL mentioned above, followed by this call:

The call to #for_external_table holds a single row of a table, in wiki-text; it's surrounded by wiki-text to create the top and bottom of the table. The presence of " | " is a standard MediaWiki trick to display pipes from within parser functions. There are much easier calls to #for_external_table that can be made, if you just want to display a line of text per data "row", but an HTML table is the standard approach.

There's one other interesting feature of #for_external_table, which is that it lets you modify specific values. You can URL-encode values by calling them with instead of just , and similarly you can HTML-encode values by calling them with.

As an example of the former, if you wanted to show links to Google searches on a set of terms retrieved, you could call:

This is required because standard parser functions can't be used within #for_external_table - so the following, for example, will not work:

#display_external_table
This function is called as:
 * 1) display_external_table is similar in concept to #for_external_table, but it passes the values in each row to a template, which handles the display.

An explanation of the parameters:
 * template - the name of the template into which each "row" of data will be passed
 * data - the data mappings between external variable and local template parameter; much like the  parameters for the other functions
 * delimiter - the separator used between one template call and the next; default is a newline. (To include newlines in the delimiter value, use "\n".)
 * intro template - a template displayed before the results set, only if there are any results
 * outro template - a template displayed after the results set, only if there are any results

For example, to display the data from the previous example in a table as before, you could create a template called "Country info row", that had the parameters "Country name", "Countries bordered", "Population" and "Area", and then call the following:

The template "Country info row" should then contain wikitext like the following: