<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Dynamically change the infotemplate on a feature layer in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/dynamically-change-the-infotemplate-on-a-feature/m-p/724269#M67234</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a feature layer that I've constructed from a url, and have applied a feature template to it to display a popup when a feature is clicked.&amp;nbsp; I also have a feature layer that I've constructed from a feature collection object (not a url) that I have applied a separate infotemplate to.&amp;nbsp; For the latter, the infotemplate displays data in a popup window for, let's say, fields X, Y, and Z; this looks something like: featureLayer.setInfoTemplate(new InfoTemplate('$X','Name: $Y &amp;lt;br/&amp;gt;Type: $Z'));&amp;nbsp; This displays a popup where the value for X is displayed as the title, and the contents are values for Y and Z.&amp;nbsp; However, sometimes the value for Y is an empty string, and when this occurs, I'd like to not display field Y in my popup.&amp;nbsp; How can I check for the value of Y when the feature is clicked so that I can dynamically alter the infotemplate to not show Y if it is an empty string?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Jason&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 29 Jan 2016 19:50:15 GMT</pubDate>
    <dc:creator>JasonLevine</dc:creator>
    <dc:date>2016-01-29T19:50:15Z</dc:date>
    <item>
      <title>Dynamically change the infotemplate on a feature layer</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/dynamically-change-the-infotemplate-on-a-feature/m-p/724269#M67234</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a feature layer that I've constructed from a url, and have applied a feature template to it to display a popup when a feature is clicked.&amp;nbsp; I also have a feature layer that I've constructed from a feature collection object (not a url) that I have applied a separate infotemplate to.&amp;nbsp; For the latter, the infotemplate displays data in a popup window for, let's say, fields X, Y, and Z; this looks something like: featureLayer.setInfoTemplate(new InfoTemplate('$X','Name: $Y &amp;lt;br/&amp;gt;Type: $Z'));&amp;nbsp; This displays a popup where the value for X is displayed as the title, and the contents are values for Y and Z.&amp;nbsp; However, sometimes the value for Y is an empty string, and when this occurs, I'd like to not display field Y in my popup.&amp;nbsp; How can I check for the value of Y when the feature is clicked so that I can dynamically alter the infotemplate to not show Y if it is an empty string?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Jason&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 29 Jan 2016 19:50:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/dynamically-change-the-infotemplate-on-a-feature/m-p/724269#M67234</guid>
      <dc:creator>JasonLevine</dc:creator>
      <dc:date>2016-01-29T19:50:15Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically change the infotemplate on a feature layer</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/dynamically-change-the-infotemplate-on-a-feature/m-p/724270#M67235</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You need to use a function for setting the content of your infoTemplate.&amp;nbsp; If you search the forum for infotemplate.setcontent, I'm sure you'll find several examples.&amp;nbsp; I end up using a function over half the time.&amp;nbsp; Instead of using ${fieldName}, you'll use graphic.attributes.fieldName.&amp;nbsp; The function can get quite long, depending on the number of attributes and how many you're checking for empty values.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;var myInfoTemplate&amp;nbsp; = new InfoTemplate("your Title");&lt;/P&gt;&lt;P&gt;myInfoTemplate.setContent(generateInfoContent);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;function generateInfoContent(graphic) {&lt;/P&gt;&lt;P&gt;var formatString = "myFieldName:" + graphic.attributes.X;&lt;/P&gt;&lt;P&gt;var checkY = graphic.attributes.Y;&lt;/P&gt;&lt;P&gt;//only appends if there is a value for attribute 'Y'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (checkY} {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; formatString += checkY;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;formatString += graphic.attributes.Z;&lt;/P&gt;&lt;P&gt;return formatString;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 29 Jan 2016 20:10:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/dynamically-change-the-infotemplate-on-a-feature/m-p/724270#M67235</guid>
      <dc:creator>TracySchloss</dc:creator>
      <dc:date>2016-01-29T20:10:01Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically change the infotemplate on a feature layer</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/dynamically-change-the-infotemplate-on-a-feature/m-p/724271#M67236</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Tracy, that's exactly what I needed!&amp;nbsp; I didn't realize you could feed a function into setContent.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-Jason&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 29 Jan 2016 22:36:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/dynamically-change-the-infotemplate-on-a-feature/m-p/724271#M67236</guid>
      <dc:creator>JasonLevine</dc:creator>
      <dc:date>2016-01-29T22:36:46Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically change the infotemplate on a feature layer</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/dynamically-change-the-infotemplate-on-a-feature/m-p/724272#M67237</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I don't think it's well documented at all, for something so versatile.&amp;nbsp; It makes me wonder what else we're overlooking!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 29 Jan 2016 22:40:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/dynamically-change-the-infotemplate-on-a-feature/m-p/724272#M67237</guid>
      <dc:creator>TracySchloss</dc:creator>
      <dc:date>2016-01-29T22:40:22Z</dc:date>
    </item>
  </channel>
</rss>

