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:
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?
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.
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.
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.
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!
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
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.
@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.
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.
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?
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)
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.
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:
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)
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.
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.
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.
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.