Address format in widget template - Front- & Back-End Development - Front- & Back-End Development - Progress Community
 Front- & Back-End Development

Address format in widget template

  • Address format in widget template
  • I'm trying to add the address field to a widget template. It is part of the related item section of the template.

    If I use :

    <div class='sfitemAddressWrp'>       
        <sf:SitefinityLabel runat="server" Text='Address:' WrapperTagName="div" HideIfNoText="true" CssClass="sfitemFieldLbl" />     
        <sf:AddressField runat="server" DataFieldName="Address" IsMapExpanded="false" AddressTemplate="#=Street# #=City# #=State# #=Country#" />
    </div>
    Nothing comes up.

     If I use

    <div class='sfitemShortTxtWrp'>
      <%# (Eval("Address") == null || Eval("Address").Equals(string.Empty)) ? "" : "<b>Address</b>" %>
      <sf:SitefinityLabel runat="server"
      Text='<%# Eval("Address")%>'
      WrapperTagName="div" HideIfNoText="true"
      CssClass="sfitemShortTxt" data-sf-field="Address"
      data-sf-ftype="ShortText" />
    </div>
    It comes in the following format:
    Address
    Street: 1949 Newton Ransom Blvd., City: Clarks Summit, Zip: 18411, CountryCode: US, StateCode: PA, Latitude: , Longitude:

    Is there a way to format the Address so it doesn't include the individual labels?

  • Hello Amanda,

    Thank you for using Telerik support. I see two question here:

    1. Why the address field doesn't work
    2. How to control the way the address is displaying with text

    Here are my answers on those:

    1. Your template looks good. Have you added the Address Field's namespace on the top of the template: 
    <%@ Register Assembly="Telerik.Sitefinity" Namespace="Telerik.Sitefinity.Web.UI.Fields" TagPrefix="sf" %>

    Also, when you say there's nothing, do you mean the whole template disappears (meaning there's an error) or do you mean that it is just the address field that is hidden?

    2. In order to display the individual items, please use code like the one below:
    <%# Eval("Address.City") %>
    <%# Eval("Address.Street") %>

    I hope this helps! 

    Regards,
    Peter
    Telerik
     
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
  • By "nothing comes up" I mean the field just shows blank with no data.

    However, you're second answer fixed the problem. Thanks!

  • Hi,

        Is there any way to display State Code in address field

    <sf:AddressField runat="server" DataFieldName="Address"IsMapExpanded="false" AddressTemplate="#=Street# #=City# #=StateCode# #=Country#" />

     

    Thanks and Regards

    Nilesh Sharma