Hi,
I`m using the format_address to generate an array
{% 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?
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
- Format your data with workflows
Also, I’d love to put you in touch with our Top Experts: Hi @sylvain_tirreau , @Anton and @zach_threadint do you have suggestions to help @JumpingKangaroo , please?
Have a lovely day and thanks so much in advance for your help!
Bérangère
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.
Anton
June 18, 2025, 10:39am
4
Hey @JumpingKangaroo ,
try this:
...
<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
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:
{% 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,
Anton
June 18, 2025, 12:10pm
6
Hey @sylvain_tirreau ,
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:
{%- 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:
{% for name, value in breakpoints.items() %}
@media screen and ({{value ~ "px" }}){
.some-class-{{ name }}{
/* some css */
}
}
{% endfor %}
The rendered output would be:
@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
My comment was more about the initial variable (see the first message of this discussion) which was this:
{% 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,
Hi Anton,
Thank you for the suggestion. This was the solution i had implemented after playing around with the code.