CMS Development

mikemaynard
Participant

Can't get HUBL Split function working properly

I'm a noob with HUBL so I'm probably missing something obvious. I'm trying to split out a contact property into an array. I can get it to work when passing a string to the split(..) filter, but it fails when I put that string in the contact property.

 

My code is:

{% set string_to_split = contact.industry %}
string to split:
{{string_to_split}}<br />
{% set names = string_to_split|split(';', 9) %}
Names: {{names}}<br />
<ul>{% for name in names %}
<li>{{ name }}</li>{% endfor %}
</ul>

{% set string_to_split = "Stephen; David; Cait; Nancy; Mike; Joe; Niall; Tim; Amanda" %}
string to split:
{{string_to_split}}<br />
{% set names = string_to_split|split(';', 9) %}
Names: {{names}}<br />
<ul>{% for name in names %}
<li>{{ name }}</li>{% endfor %}
</ul>

 

The first section doesn't work: the split function doesn't create multiple rows on the array, and just puts the whole string into one variable:

 

string to split: Stephen; David; Cait; Nancy; Mike; Joe; Niall; Tim; Amanda
Names: [Stephen; David; Cait; Nancy; Mike; Joe; Niall; Tim; Amanda]

  • Stephen; David; Cait; Nancy; Mike; Joe; Niall; Tim; Amanda

 

But when i set the variable with a constant value, everything works as expected:

 

string to split: Stephen; David; Cait; Nancy; Mike; Joe; Niall; Tim; Amanda
Names: [Stephen, David, Cait, Nancy, Mike, Joe, Niall, Tim, Amanda]

  • Stephen
  • David
  • Cait
  • Nancy
  • Mike
  • Joe
  • Niall
  • Tim
  • Amanda

 

I just can't see why the split function doesn't work the first time as the variable I'm passing is (on the face of it) the same both times. So why does the split function work on one, but not the other?

 

I'd really appreciate any help you can give


Thanks


Mike

 

 

 

22 Replies 22
Jsum
Key Advisor

Can't get HUBL Split function working properly

hey @mikemaynard,

 

It might help if you told us what you are trying to accomplish. Are you wanting to list out all industries that are tied to your contacts?

 

I don't have much experience dealing with contacts or contact properties but I think that, while you can use contact.property to customize a page for the contact viewing it, you cannot use the contact variable to access your contacts database. For instance, I don't believe that you could output a list of all of the names of your contacts or other information onto a page. I did test this and it doesn't seam to work. 

 

Hubspot does have an api that includes the contacts api but their api's main purpose is for outside websites so it isn't easily integrateable into your portal and it also is not available by default. I believe there is an extra charge. 

 

Let me ask you this, does {{ contact.industry }} output anything to your page? If it works how I think you are wanting it to work then it would list all industries in you contacts list. if it works like I think it works then it will only output the industry tied to your contact profile, provided that you are a contact with the property "industry" filled out in your contact profile. 

mikemaynard
Participant

Can't get HUBL Split function working properly

In response to the question:

 


  

Let me ask you this, does {{ contact.industry }} output anything to your page? If it works how I think you are wanting it to work then it would list all industries in you contacts list. if it works like I think it works then it will only output the industry tied to your contact profile, provided that you are a contact with the property "industry" filled out in your contact profile. 




 

If you look at the outputs, I'm outputing the variable {{string_to_split}} in both cases and they look exactly the same, but in one case split(..) works and in the other it doesn't do anything. I'm guessing there may be something hidden that I'm not seeing, but on the face of it the variable has EXACTLY the same contents, but the result of the split function is completely different.

0 Upvotes
EricSalvi
HubSpot Employee
HubSpot Employee

Can't get HUBL Split function working properly

@mikemaynard
Maybe before the |split filter, I have had success in the past with others to squeeze in the |string filter first. Could look like this

string_to_split|string|split(';', 9)

Maybe that will work?
@Jsum I can see he already showed the example output in the initial question.

0 Upvotes
mikemaynard
Participant

Can't get HUBL Split function working properly

Thanks for helping @EricSalvi. Unfortunately it didn't work.

 

I tried: 

{% set names = string_to_split|string|split(';', 9) %}

and unfortunately the behaviour is still exactly the same. it splits string_to_split when it's assigned with a constant value, but not with the contact.industry property.

 

0 Upvotes
Jsum
Key Advisor

Can't get HUBL Split function working properly

@mikemaynard can you share the output?

0 Upvotes
mikemaynard
Participant

Can't get HUBL Split function working properly

When using {% set string_to_split = contact.industry %}

 

string to split: Stephen; David; Cait; Nancy; Mike; Joe; Niall; Tim; Amanda
Names: [Stephen; David; Cait; Nancy; Mike; Joe; Niall; Tim; Amanda]

  • Stephen; David; Cait; Nancy; Mike; Joe; Niall; Tim; Amanda

 

When using {% set string_to_split = "Stephen; David; Cait; Nancy; Mike; Joe; Niall; Tim; Amanda" %}

 

string to split: Stephen; David; Cait; Nancy; Mike; Joe; Niall; Tim; Amanda
Names: [Stephen, David, Cait, Nancy, Mike, Joe, Niall, Tim, Amanda]

  • Stephen
  • David
  • Cait
  • Nancy
  • Mike
  • Joe
  • Niall
  • Tim
  • Amanda

 

As you can see, {{string_to_split}} looks to be identical in both cases, but when I create {{names}} using split(...), the first time it's just a string and isn't split, whereas the second time (setting the text as a constant) I've created an array by splitting the string with the ";"s. 

 

I did cut and paste the string into contact.industry for this contact that I'm testing with, so it should be the same. And the output looks the same. But presumably there is some difference that i just can't see!

 

Thanks for your help.

0 Upvotes
Jsum
Key Advisor

Can't get HUBL Split function working properly

@mikemaynard, that is confusing me. Why does the contact.industry variable print out a list of names?

0 Upvotes
mikemaynard
Participant

Can't get HUBL Split function working properly

Hi @Jsum you are reading too much into the property and the values. This is just a test. I will create a new custom field, and the contents will be completely different once I get this to work. I just used a convenient string (the one used in example HS code) and convenient property (something I display for all contacts so it's easy to change) for the test. The name and content are irrelevant

0 Upvotes
Jsum
Key Advisor

Can't get HUBL Split function working properly

@mikemaynard,

 

No I don't believe that I am because I as attempted to explain to you several times, you probably won't be able to use the contact variable the way that you are attempting to use it. And besides, your code example above clearly states that you ARE using the contact.industry variable and it is printing out a list of names. Unless you have assigned a bunch of names to the industry fields of your contacts profiles, or you overwrote the variable with the names and didn't show this, then your output makes absolutely no sense. There is no other way that you could be retrieving a list of names from that variable. 

 

The reason I am so concerned about your output is that you seam to think that your issue is with the filter you are using while I think your issue is related to the above. Without understanding what you are trying to do, and what you have already tried, I can't very well help you find a solution. 

 

All I can say is that if it is an array you output the contents with a for loop and so filtering it is not necessary. If it's a string then splting will work. 

<li>{{ array.property[0] }}</li>
<li>{{ array.property[1] }}</li>
<li>{{ array.property[2] }}</li>

or

{% for item in array.property %}
    <li>{{ item }}</li>
{% endfor %}
0 Upvotes
mikemaynard
Participant

Can't get HUBL Split function working properly

@Jsum - replying separately to the comment about arrays:

 

In both cases I am creating a string called string_to_split and then creating an array using split(...). When I assign the string using "...." it works perfectly. When i assign the string using the contact property it does not. In both cases I have *definitely* assigned a string (checked using pprint) and in both cases the string *definitely* looks the same (again checked using pprint as well as displaying the variable). But in one case the split(...) produces an array and in the other it does not. If I could produce an array when using the contact property I completely agree that displaying the elements is trivial.


Thanks

 

Mike

0 Upvotes
EricSalvi
HubSpot Employee
HubSpot Employee

Can't get HUBL Split function working properly

Just to share my test on my own account. I set up this code on a landing page template in a HubL module. Converted the existing industry property to multi-checkbox. Went into a test contact and selected the options I wanted. Then when I viewed the page as a specific contact I noticed the string was not separated by (;) but instead (,)

Changed the split to look for a comma instead of the semicolon and it worked.
Screen Shot 2017-06-23 at 11.15.08 AM.png

0 Upvotes
mikemaynard
Participant

Can't get HUBL Split function working properly

Thanks @EricSalvi. I should have tested a LP earlier, but never thought the results would be different.

 

I've been working on an email. So I cut and pasted my code into a landing page. IT WORKED. (FWIW the separator makes no difference, my original code with the semicolon separator works fine on a landing page too).

 

So: GOOD NEWS - my code is OK

BAD NEWS: there appears to be a bug when using HubL to create emails. Is there a way to get this fixed asap?

0 Upvotes
ryan3
Participant

Can't get HUBL Split function working properly

I just ran into this issue myself, spending way too much time trying to figure out why split(..) would just silently fail and always return a string.  For anyone else stumbling across this, I then found this bug report saying it is not a bug, but that the feature does not exist for emails:  https://community.hubspot.com/t5/COS-Design-Support/Split-filter-bug-report-in-Email-Module/m-p/2031...  

 

It seems like the ability to create any kind of custom dynamic emails based on customer properties is essentially impossible with HubSpot without this functionality, unless you're just using a simple string.

 

@mikemaynard Where you ever able to find a work around?  I'm trying to do the same thing as you... work with a simple array of data from a customer property (which btw you explained very clearly in your original post) 

mikemaynard
Participant

Can't get HUBL Split function working properly

Hi @ryan3

We're looking at using Scribe (https://www.scribesoft.com/). It is more than capable of doing what we need, although it is reletively expensive if this is all we use it for. I've heard some good things about the team, and apparently support is very good.

Mike

 

 

derekcavaliero
Top Contributor | Diamond Partner
Top Contributor | Diamond Partner

Can't get HUBL Split function working properly

Holy cow I am not crazy - I have been troubleshooting the exact same thing @mikemaynard.

 

Here is the use case.

 

We have a library of resources on a site. A user can fill out a form to access a resource. The pages we have the resources living on are built on WordPress and have some nifty dynamic php behind the scene that outputs 3 related resources to the current resource on the page.

 

The marketing team wants to output these resources inside the emails sent via HubSpot's workflows. The way I was envisioning this working would be to send a blob of CSV data through a hidden text area (a custom contact property) on the form submission and then parse it using a custom HubL email module and loop through it. 

 

There are 2 really screwy things about HubL:

 

  1. You can't parse or typecast a variable into any other type than a string UNLESS you manually parse the string using |split (no filters exist to my knowledge)

  2. That HubSpot magically removes all filter capabilities for email.

 

I was so pumped that I thought I could get this to work... HubSpot - please allow the use of some filters in email... This is stopping us from making our drip campaigns truely "automated" with how our CMS organizes content.

Derek Cavaliero
Director of Engineering

WebMechanix
www.webmechanix.com
GBSchris
Participant

Can't get HUBL Split function working properly

This is unfortunate,

we have a very similar use case @derekcavaliero did you come up with any other ideas to near your goal?

 

The wound of learning this is not possible with Hubl in an email is still fresh for me!

0 Upvotes
mikemaynard
Participant

Can't get HUBL Split function working properly

There's not much you can really do to overcome this. The two possible ways of having more dynamic content are either adding content to a contact property or using smart lists to switch content in and out of an email. Either way, you'll struggle to use complex rules or individually personalise content.

 

The only other way I can think is to implement the HubL logic in something like Scribe Online. It's a great product that would be able to apply complex rules to create content (which would be HTML) in contact properties. But it's going to cost you around $3-400 per month, I believe.

0 Upvotes
GBSchris
Participant

Can't get HUBL Split function working properly

Thanks @mikemaynard,

Agreed, using the built in personalization tags along with a custom multi-check contact property is where we have ended up. It is not ideal but a happy medium for us right now.  

 

As you have mentioned Scribe definitely would meet our needs, but we would need to ramp up our requirements to justify the cost. Thanks for the link though I'll take a deeper look at their solution.

0 Upvotes
Jsum
Key Advisor

Can't get HUBL Split function working properly

If your resource's would using Hubspots blog system you could simply use a blogs by topic function, passing the related topic to the topic to filter by part of the function.  I've done similar before.

0 Upvotes
mikemaynard
Participant

Can't get HUBL Split function working properly

@Jsum I'm not being clear, and so I'm really sorry.

 

Let's change the string to a list of industries: 

{% set string_to_split = "Media; Marketing; Advertising; Sales; Digital; Web; PR; CPC; SEO" %}

 

I want to display the list of industries as a bulleted list in the email. If I assign string_to_split as above then it displays as:

  • Media
  • Marketing
  • Advertising
  • Sales
  • Digital
  • Web
  • PR
  • CPC
  • SEO

If I cut and paste the same string into contact.industry,  and assign the string like this:

{% set string_to_split = contact.industry %}

then the split(...) filter does not work, and the industries are all on the same bullet:

  • Media; Marketing; Advertising; Sales; Digital; Web; PR; CPC; SEO

Yet it appears that the variable string_to_split is assigned exactly the same value. 

 

Does this make more sense to you now?

 

Thanks


Mike

0 Upvotes