# Using format\_address

**URL:** <https://community.hubspot.com/t/using-format-address/134648>\
**Category:** CMS Development\
**Created:** [June 17, 2025, 1:02pm UTC](https://community.hubspot.com/t/using-format-address/134648 "2025-06-17T13:02:36Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![JumpingKangaroo](https://avatars.discourse-cdn.com/v4/letter/j/7ba0ec/32.png) [@JumpingKangaroo](https://community.hubspot.com/u/JumpingKangaroo)\
**Post date:** [June 17, 2025, 1:02pm UTC](https://community.hubspot.com/t/using-format-address/134648/1 "2025-06-17T13:02:36Z")

</div>

Hi,  
I`m using the format\_address to generate an array

```lia-code-sample
{% set address_lines = format_address(
 QUOTE.hs_locale or 'en-us',
 {
 address: module.show_company_address and BUYER_COMPANY.address ? BUYER_COMPANY.address : '',
 address2: module.show_company_address and BUYER_COMPANY.address2 ? BUYER_COMPANY.address2 : '',
 city: module.show_company_city_state_zip and BUYER_COMPANY.city ? BUYER_COMPANY.city : '',
 state: module.show_company_city_state_zip and BUYER_COMPANY.state ? BUYER_COMPANY.state : '',
 zip: module.show_company_city_state_zip and BUYER_COMPANY.zip ? BUYER_COMPANY.zip : '',
 country: module.show_company_country and BUYER_COMPANY.country ? BUYER_COMPANY.country : ''
 }
 )
%}

<address style="font-style: normal">
 {% for line in address_lines %}
 {{line}} <br>
 {% endfor %}
</address>

```

This gives me this output.

**Sample company**

123 Sample Town, Suite 123  
San Francisco, California 90000  
United States

What i would like is the address2 to be on a 2nd line like this

**Sample company**

123 Sample Town,  
Suite 123,  
San Francisco, California 90000  
United States

Is there a way to change the format\_address function?

---

<div class="post-metadata">

**Author:** ![Berangere](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/berangere/32/220784_2.png) [@Berangere](https://community.hubspot.com/u/Berangere)\
**Post date:** [June 18, 2025, 7:03am UTC](https://community.hubspot.com/t/using-format-address/134648/2 "2025-06-18T07:03:01Z")

</div>

Hi @JumpingKangaroo, I hope that you are well!  
Great question, thanks for asking the HubSpot Community!  
To start with, I’d like to share these resources that might be of interest to you:  
- [HubL functions: format\_address](https://developers.hubspot.com/docs/reference/cms/hubl/functions#format_address)  
- [Format your data with workflows](https://knowledge.hubspot.com/workflows/format-your-data-with-workflows)  
Also, I’d love to put you in touch with our Top Experts: Hi [@sylvain\_tirreau](https://community.hubspot.com/t5/user/viewprofilepage/user-id/601366), @Anton and [@zach\_threadint](https://community.hubspot.com/t5/user/viewprofilepage/user-id/324811) do you have suggestions to help @JumpingKangaroo, please?  
Have a lovely day and thanks so much in advance for your help!  
Bérangère

---

<div class="post-metadata">

**Author:** ![sylvain\_tirreau](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/sylvain_tirreau/32/67408_2.png) [@sylvain\_tirreau](https://community.hubspot.com/u/sylvain_tirreau)\
**Post date:** [June 18, 2025, 9:49am UTC](https://community.hubspot.com/t/using-format-address/134648/3 "2025-06-18T09:49:46Z")

</div>

Hi,

Unfortunately, you have no way to change this, because it’s pre-formatted precisely to respect formatting conventions. If I were you, I would create my own table myself to control the display of the data.

---

<div class="post-metadata">

**Author:** ![Anton](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/anton/32/103167_2.png) [@Anton](https://community.hubspot.com/u/Anton)\
**Post date:** [June 18, 2025, 10:39am UTC](https://community.hubspot.com/t/using-format-address/134648/4 "2025-06-18T10:39:09Z")

</div>

Hey @JumpingKangaroo,

try this:

```lia-code-sample
...
<address style="font-style: normal">
 {% for line in address_lines %}
 {{ line.address }}, <br>
 {% if line.address2 %}
 {{ line.address2 }}, <br>
 {% endif %}
 {{ line.city }}, {{ line.state }} {{ line.zip }}, <br>
 {{ line.coutry }}
 {% endfor %}
</address>

```

best,

Anton

---

<div class="post-metadata">

**Author:** ![sylvain\_tirreau](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/sylvain_tirreau/32/67408_2.png) [@sylvain\_tirreau](https://community.hubspot.com/u/sylvain_tirreau)\
**Post date:** [June 18, 2025, 11:14am UTC](https://community.hubspot.com/t/using-format-address/134648/5 "2025-06-18T11:14:23Z")

</div>

Hi @Anton ,

Why would your example work? address\_lines is a list of strings, not a list of objects. Or I’m missing something.

Your example works if he does this:

```lia-code-sample
{% set address_lines = [{
 address: module.show_company_address and BUYER_COMPANY.address ? BUYER_COMPANY.address : '',
 address2: module.show_company_address and BUYER_COMPANY.address2 ? BUYER_COMPANY.address2 : '',
 city: module.show_company_city_state_zip and BUYER_COMPANY.city ? BUYER_COMPANY.city : '',
 state: module.show_company_city_state_zip and BUYER_COMPANY.state ? BUYER_COMPANY.state : '',
 zip: module.show_company_city_state_zip and BUYER_COMPANY.zip ? BUYER_COMPANY.zip : '',
 country: module.show_company_country and BUYER_COMPANY.country ? BUYER_COMPANY.country : ''
 }]
%}

```

Best,

---

<div class="post-metadata">

**Author:** ![Anton](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/anton/32/103167_2.png) [@Anton](https://community.hubspot.com/u/Anton)\
**Post date:** [June 18, 2025, 12:10pm UTC](https://community.hubspot.com/t/using-format-address/134648/6 "2025-06-18T12:10:56Z")

</div>

Hey [@sylvain\_tirreau](https://community.hubspot.com/t5/user/viewprofilepage/user-id/601366),

I’d say because when you’re looping through a list of strings the for-loop creates an object for each instace. Therefore the “set XYZ” info can be accessed in the actual loop.

Simple example:

```lia-code-sample
{%- set breakpoints = {
 "sm" :"480", 
 "md" :"768", 
 "lg" :"1024",
 "xl" :"1400"
} 
-%}

```

by it self can be accessed via

`{{breakpoints.sm}}`

if you like to create a for-loop with all the individual infos, you have to write it like this:

```lia-code-sample
{% for name, value in breakpoints.items() %}
@media screen and ({{value ~ "px" }}){
.some-class-{{ name }}{
/* some css */
}
}
{% endfor %}

```

The rendered output would be:

```lia-code-sample
@media screen and (min-width:480px){
.some-class-sm{
/* some css */
}
}

@media screen and (min-width:768px){
.some-class-md{
/* some css */
}
}

@media screen and (min-width:1024px){
.some-class-lg{
/* some css */
}
}

@media screen and (min-width:1400px){
.some-class-xl{
/* some css */
}
}

```

best,

Anton

---

<div class="post-metadata">

**Author:** ![sylvain\_tirreau](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/sylvain_tirreau/32/67408_2.png) [@sylvain\_tirreau](https://community.hubspot.com/u/sylvain_tirreau)\
**Post date:** [June 18, 2025, 12:17pm UTC](https://community.hubspot.com/t/using-format-address/134648/7 "2025-06-18T12:17:02Z")

</div>

My comment was more about the initial variable (see the first message of this discussion) which was this:

```lia-code-sample
{% set address_lines = format_address(
 QUOTE.hs_locale or 'en-us',
 {
 address: module.show_company_address and BUYER_COMPANY.address ? BUYER_COMPANY.address : '',
 address2: module.show_company_address and BUYER_COMPANY.address2 ? BUYER_COMPANY.address2 : '',
 city: module.show_company_city_state_zip and BUYER_COMPANY.city ? BUYER_COMPANY.city : '',
 state: module.show_company_city_state_zip and BUYER_COMPANY.state ? BUYER_COMPANY.state : '',
 zip: module.show_company_city_state_zip and BUYER_COMPANY.zip ? BUYER_COMPANY.zip : '',
 country: module.show_company_country and BUYER_COMPANY.country ? BUYER_COMPANY.country : ''
 }
 )
%}

```

Your code doesn’t work with this variable; you need to adapt it to make it work.

That was the whole point of my approach. 😉

Best,

---

<div class="post-metadata">

**Author:** ![JumpingKangaroo](https://avatars.discourse-cdn.com/v4/letter/j/7ba0ec/32.png) [@JumpingKangaroo](https://community.hubspot.com/u/JumpingKangaroo)\
**Post date:** [June 18, 2025, 11:17am UTC](https://community.hubspot.com/t/using-format-address/134648/8 "2025-06-18T11:17:23Z")

</div>

Hi Anton,

Thank you for the suggestion. This was the solution i had implemented after playing around with the code.
