Address format in widget template

Posted by Community Admin on 05-Aug-2018 14:03

Address format in widget template

All Replies

Posted by Community Admin on 03-Oct-2014 00:00

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?

Posted by Community Admin on 08-Oct-2014 00:00

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
 

Posted by Community Admin on 09-Oct-2014 00:00

By "nothing comes up" I mean the field just shows blank with no data.

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

Posted by Community Admin on 26-Jan-2017 00:00

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

This thread is closed