Hide Table of Contents
esri/dijit/util
esri/layer/pixelFilters
esri/process
esri/workers
Class: InfoTemplate

require(["esri/InfoTemplate"], function(InfoTemplate) { /* code goes here */ });

Description

(Added at v1.0)
An InfoTemplate contains a title and content template string used to transform Graphic.attributes into an HTML representation. The Dojo syntax ${} performs the parameter substitution. In addition, a wildcard ${*} can be used as the template string. The wildcard prints out all of the attribute's name value pairs. The default behavior on a Graphic is to show the Map's InfoWindow after a click on the Graphic. An InfoTemplate is required for this default behavior.

Samples

Search for samples that use this class.

Subclasses

Constructors

NameSummary
new InfoTemplate()Creates a new empty InfoTemplate object.
new InfoTemplate(title, content)Creates a new InfoTemplate object.
new InfoTemplate(json)Creates a new InfoTemplate object using a JSON object.

Properties

NameTypeSummary
contentString | FunctionThe template for defining how to format the content used in an InfoWindow.
titleString | FunctionThe template for defining how to format the title used in an InfoWindow.

Methods

NameReturn typeSummary
setContent(template)InfoTemplateSets the content template.
setTitle(template)InfoTemplateSets the title template.
toJson()ObjectConverts object to its ArcGIS Server JSON representation.
Constructor Details

new InfoTemplate()

Creates a new empty InfoTemplate object.

new InfoTemplate(title, content)

Creates a new InfoTemplate object. All parameters are required and must be specified in the order given.
Parameters:
<String | Function> title Required The template for defining how to format the title used in an InfoWindow.
<String | Function> content Required The template for defining how to format the content used in an InfoWindow.
Sample:

Use a wildcard to automatically include all the attribute's name value pairs.

require([
  "esri/InfoTemplate", ... 
], function(InfoTemplate, ... ) {
  var infoTemplate = new InfoTemplate("Attributes", "${*}");
  ...
});

Display only the specified fields.

require([
  "esri/InfoTemplate", ... 
], function(InfoTemplate, ... ) {
  var infoTemplate = new InfoTemplate("Attributes", "State Name: ${STATE_NAME}<br>Population: ${Pop2001}");
  ...
});

new InfoTemplate(json)

Creates a new InfoTemplate object using a JSON object.
Parameters:
<Object> json Required JSON object representing the InfoTemplate.
{title:"Test Title", content:"Test Content"}
Sample:
require([
  "esri/InfoTemplate", ... 
], function(InfoTemplate, ... ) {
  var json = {title:"Attributes",content:"State Name: ${STATE_NAME}<br>Population: ${POP2001}"}
  var infoTemplate = new InfoTemplate(json);
  ...
});
Property Details

<String | Function> content

The template for defining how to format the content used in an InfoWindow. Starting with version 2.2 the content for an InfoWindow can be defined using either a string or a function. This provides the developer the ability to easily format and customize the InfoWindow contents. Prior to 2.2, only a string could be specified. View the Format Info Window Content help topic for more details.

<String | Function> title

The template for defining how to format the title used in an InfoWindow. You can format the title by specifying either a string value or a function. See the content property for more details. In most cases, the title is specified as either a simple string or a function that returns a simple string. View the Format Info Window Content help topic for more details.
Method Details

setContent(template)

Sets the content template. View the Format Info Window Content help topic for more details.
Return type: InfoTemplate
Parameters:
<String | Function> template Required The template for the content.
Sample:
infoTemplate.setContent("State Name: ${STATE_NAME}");

setTitle(template)

Sets the title template. View the Format Info Window Content help topic for more details.
Return type: InfoTemplate
Parameters:
<String | Function> template Required The template for the title.
Sample:

infoTemplate.setTitle("Feature Attributes");

toJson()

Converts object to its ArcGIS Server JSON representation.
Return type: Object