Querying Company File-type field in email template

Hi,

I want to send an email to contacts. That email must contain an image which is stored in a custom field in the contact’s Company object.

I tried accessing the property directly :

<p>
	Test : {{ company.pie_chart }}
	Test : {{ contact.company.pie_chart }}
</p>

It returns nothing. I tried using the personalization tokens :

{% set pie_chart = personalization_token("company.pie_chart") %}

That one works ! BUT, it doesn’t return an image or a URL, only a file ID. I tried using that ID to get the file itself :

{% if pie_chart %}
	{% set pie_chart_file = file_by_id(pie_chart) %}
	{% set pie_chart_url = pie_chart_file.friendlyUrl %}
	<img src="{{ pie_chart_url }}" />
{% endif %}

But this doesn’t work. I think the personalization token gets processed after the file_by_id() function, so the result of personalization_token cannot be passed as an argument to file_by_id().

Is there another way to get the image stored in the file field to be embedded in the email as a normal image ?

Thank you for your help.

Hey @LeKevoid - thanks for posting in the Community!
I’d like to tag in some Community experts to see if they have any insight on how we can embed these images. @Anton, @ashleyidesign, and @nickdeckerdevs1 - any thoughts here?
Shane, Senior Community Moderator

Hi @LeKevoid ,

Your file_by_id(personalization_token(“company.pie_chart”)) fails because personalization tokens process after Hubl functions.

How I would solve it:

  1. Trigger HubSpot workflow
  2. Custom code action to get the File URL using HubSpot API
  3. Send Email action → pass dynamic pie_chart_url token directly from workflow data (no extra property needed).
  4. Use that token ({{ workflow.pie_chart_url }}) in your email <img src=“…”>.

Did my post resolve your question? If so, please consider marking it as the accepted solution to help others in the community.
Kind regards
Dennis