1

I have a custom infoWindow on a cartodb.js map which uses moustache templates to populate the fields in the infoWindow. In it I have a link to tweet a correction to the map which I populate with the relevant fields. I want to make the name of the {{country}} a hash tag but in order to do this I need to strip the spaces from the field in the case of countries with more than one word e.g. Democratic Republic of Congo which I would like to appear as #DemocraticRepublicofCongo. Is there a way to perform javacript operations like .replace(/\s+/g, '') on a moustache template? The infoWindow code follows and the full web page can be found at https://afterfibre.nsrc.org/af_dev.html with full source at https://github.com/stevesong/nsrc-afterfibre/blob/master/af_dev.html

  <div class="cartodb-popup v2 orange">
  <a href="#close" class="cartodb-popup-close-button close">x</a>
  <div class="cartodb-popup-content-wrapper">
    <div class="cartodb-popup-header">
      <div class="rTableTitle">
          <div class="rTableRow">
            <div class="rTableCell"><img src="/flag/{{iso2}}.png"></div><div class="rTableCellTitle"><h4 style="font-size: larger;"><a href="{{weburl}}" target="_blank">{{operator}}</a></h4></div>
          </div>
        </div>
      </div>
    </div>
    <div class="cartodb-popup-content">
      <!-- content.data contains the field info -->
       <div class="rTable">
        <div class="rTableRow">
          <div class="rTableCellRight"><h4 style="color: green;">Phase</h4></div><div class="rTableCell">{{phase_name}}</div>
        </div>
        <div class="rTableRow">
          <div class="rTableCellRight"><h4 style="color: green;">Country</h4></div><div class="rTableCell">{{country}}</div>
        </div>
        <div class="rTableRow">
          <div class="rTableCellRight"><h4 style="color: green;">Owner</h4></div><div class="rTableCell">{{orgname}}</div>
        </div>
        <div class="rTableRow">
          <div class="rTableCellRight"><h4 style="color: green;">Type</h4></div><div class="rTableCell">{{type}}</div>
        </div>
        <div class="rTableRow">
          <div class="rTableCellRight"><h4 style="color: green;">In Service</h4></div><div class="rTableCell">{{go_live}}</div>
        </div>
        <div class="rTableRow">
          <div class="rTableCellRight"><h4 style="color: green;">Source</h4></div><div class="rTableCell"><a href="{{source_url}}" target="_blank">map</a></div>
        </div>
        <div class="rTableRow">
          <div class="rTableCellRight"><h4 style="color: green;">Contribute</h4></div><div class="rTableCell"><a href="http://twitter.com/home?status=%23AfTerFibre map for {{phase_name}} {{orgname}} needs updating! %23{{country}}" target="_blank">Tweet a correction!</a></div>
        </div>            
        <p></p>
      </div>
    </div>
  </div>
  <div class="cartodb-popup-tip-container"></div>
</div>
  • Perhaps you can create a new column and use SQL to do this? postgresql.org/docs/current/static/functions-string.html – DPSSpatial Feb 7 '16 at 19:31
  • Thanks @mapBaker. I didn't think of that. Something like UPDATE af_fibrephase SET countryHash = regexp_replace(country, '\s+','','g') does indeed work although it means that each new record news this new field created. If possible, I'd prefer create the hashtag dynamically if I can. – SteveSong Feb 8 '16 at 12:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.