HubL Reference

Table of contents
Close

Pulling HubSpot CRM Data Into Your CMS Pages

The HubSpot CMS allows you to pull information directly from your HubSpot CRM objects right into your website pages using either the crm_object HubL function or the crm_objects HubL function. The crm_object function pulls a single CRM object and can be called up to 10 times on a page to pull contacts, products, companies, deals, tickets or quotes object information into the page. If you need to pull more than 10 CRM objects, the crm_objects function can pull up to 100 objects and can be called up to 10 times per page, for a maximum of 1000 CRM objects. 

For security purposes, only Product objects can be retrieved on a publicly accessible page. Any other object type must be hosted on a page which is either password protected or requires a CMS Membership login.

The following example walks through creating a private page requiring registration and using the crm_object function to pull in data for the logged-in contact, or a specified contact. 

Create a page

Create a new Module

Create a new module to house the logic for displaying contact record data. 

crm_object module

The crm_object HubL function can either be passed a specified contact to render data for or, it can render data for the logged-on contact. This example module allows a marketer to specify if the contact record data should be that of a specific contact, or the logged-in contact. 

The module has two fields:

  1. requesting_contact (boolean) - Specifies if the contact data to display is for the logged-in contact or a specified contact. This field should be required and checked by default. 
  2. specified_contact_email (text) - Used to specify a contact by email to display data for, if not displaying data for the logged-in contact. This field should be conditionally displayed if requesting_contact equals false

The logic for rendering data based on the selections in the page editor would look something like:


{% if module.requesting_contact %}
  {% set membership_contact = crm_object('contact', request.contact.contact_vid, 'firstname,lastname') %}
  Logged-in contact name: {{ membership_contact.firstname }} {{ membership_contact.lastname }}
{% else %}
  {% set query = 'email=' ~ module.specified_contact_email %}
  {% set specified_contact = crm_object("contact", query, "firstname,lastname") %}
  Specified contact name: {{ specified_contact.firstname }} {{ specified_contact.lastname }}
{% endif %}

Add the module to a page

Either to the template or the page level, add your newly created module. If you added the conditional logic to the module fields, the editing experience will be:

Contact Data Module

If the intention of the page being created is to display data to the visiting contact, it is highly recommended to use the logged-in contact method of selecting contact data to display. Using the specified contact method means contacts with access to the page could see data for other contacts.

Note: If the specified contact does not match a contact in your HubSpot CRM, no contact data will be available. 

Note: The logged-in method if displaying data will only work on live pages, not in previews of the page or the page editor. 

Set audience access rules for the page

Follow the "Control audience access to pages" instructions to make the page "Private - Registration required". NOTE: This will send a registration email to any contacts who are granted access to the page.