Skip to Content

Find the deals associated with a contact on a HubSpot membership page

In HubSpot, you can create pages where users can view their own information (retrieved from the CRM) when logged in. For example, the deals associated with their contact record.

Note: this functionality is available if you have access to Membership pages, available on CMS Enterprise.

Get a contact's data

To get a contact's data on your HubSpot CMS page, you can use the crm_object or crm_objects HubL functions. For security reasons, this can only be done for contact information and associated deals on a password-protected or membership login page.

To get a contact's first and last name using the crm_object function, you would write something like the following code, with the parameters:

  • Object Type - 'contact' in this case
  • Object ID - retrieved from a logged-in member in this case - request.contact.contact_vid (this pulls the visitor's unique ID from the request)
  • Object Properties you'd like to retrieve (e.g. 'firstname,lastname'):
{% if request_contact.is_logged_in and request.contact.contact_vid %}

  {% set membership_contact = crm_object('contact', request.contact.contact_vid, 'firstname,lastname') %}

  <div class="profile">
    <p>Full Name: {{ membership_contact.firstname }} {{ membership_contact.lastname }}</p>
  </div>

{% endif %}

Note: on membership sites, wrap the above code in the condition if request_contact.is_logged_in and request.contact.contact_vid to ensure that the visitor is a logged in member and has a unique visitor ID. Learn more.

Get a contact's associated deals

Now that we've retrieve the contact's information, to get their associated deals, use the crm_associations HubL function and write something like the following code, with the parameters:

  • Object ID - again, retrieved from a logged-in member in this case request.contact.contact_vid
  • Object Association Category - 'HUBSPOT_DEFINED' in this case
  • Association Type ID - in this case 4, "Contact to deal"
  • Query String - you can leave this empty or add queries as needed
  • Object Properties you'd like to retrieve (e.g. 'dealname,amount')
{% if request_contact.is_logged_in and request.contact.contact_vid %}

  {% set membership_contact = crm_object('contact', request.contact.contact_vid, 'firstname,lastname') %}
  {% set associated_deals = crm_associations(request.contact.contact_vid, 'HUBSPOT_DEFINED', 4, '', 'dealname,amount') %} 

  <div class="profile">
    <p>Full Name: {{ membership_contact.firstname }} {{ membership_contact.lastname }}</p>
  </div>

  <div class="deals">
    {% for deal in associated_deals.results %}
    <div class="deal">
      <p>Deal name: {{ deal.dealname }}</p>
      <p>Amount: {{ deal.amount }}</p>
    </div>
  {% endfor %}  
  </div>

{% endif %}

Put the above two code snippets together:

{% if request_contact.is_logged_in and request.contact.contact_vid %}

    {% set membership_contact = crm_object('contact', request.contact.contact_vid, 'firstname,lastname') %}
    {% set associated_deals = crm_associations(request.contact.contact_vid, 'HUBSPOT_DEFINED', 4, '', 'dealname,amount') %} 

    <div class="profile">
        <p>Full Name: {{ membership_contact.firstname }} {{ membership_contact.lastname }}</p>
    </div> 

    <div class="deals">
    {% for deal in associated_deals.results %}
    <div class="deal">
        <p>Deal name: {{ deal.dealname }}</p>
        <p>Amount: {{ deal.amount }}</p>
    </div>
    {% endfor %}  
    </div>

{% endif %}

And they should render the following HTML when a user is logged in:

<div class="profile">
  <p>Full Name: Stephanie O'Gay Garcia</p>
</div>

<div class="deals">
  <div class="deal">
    <p>Deal name: Test Deal 1</p>
    <p>Amount: $123</p>
  </div>
  <div class="deal">
    <p>Deal name: Test Deal 2</p>
    <p>Amount: $456</p>
  </div>
</div>

Other Objects

You can retrieve data from other object types (product, marketing_event, contact, company, deal, ticket, quote or custom if you have an Enterprise account) and their associations by using variations on the code above with the relevant parameters.

←  Previous Article

Hiding HubSpot modules on mobile/desktop at template level

Next Article  →

How to combine posts from multiple HubSpot blogs in a custom module

Contact

Get help from a HubSpot CMS Expert

  • Custom HubSpot themes and reusable and easy-to-use HubSpot templates and modules
  • Technical support and guidance on the HubSpot CMS