I've been playing around with the capabilities of HubDB and it's pretty exciting. However, I'm trying to see if I can expand on the team directory idea in one very specific way.
I'd like to make team member pages that leverage the database. My plan (until more functionality is added) is to be able to have a choice dropdown on the team member page that would let me select a team member's name. The name would just be a cell in the database. So ideally, I'd be able to something like this:
Pull full names from database
store in array/variable
Use that array/variable in the choice dropdown, like so
Then I'd be able to pick whose page I'm creating from that dropdown, and let the rest of it populate based on that one choice.
Currently, it looks like there's not a good way to get everyone's names out of HubDB except from within a for loop, which then means I can't call that variable later because it's out of scope. However, it's moot because you can't call an array as a choice dropdown. If it isn't predefined, there's not a way to use it as the choice.
So, TL;DR:
Can I access everything in one HubDB column outside of a for loop?
If not, can I transfer the variable value from inside to outside the loop?
Also, can I use that variable/information as a choice dropdown?
has anyone thought about this recently? currently having to api call, and then painstakingly format my hubdb row names and id's using regex. and I have to do this like every time my marketers add new rows to the db.
Note the choices = {{variable}} has to go at the end as it breaks because there are no quotes around it
Matthew Scott Head of Development
B2B marketing agency: Specialist B2B content marketing and demand generation for SaaS vendors and HubSpot Users | Deeply Digital | HubSpot Partner since 2010
Hi Parker - quick clarifying question: where do you plan to use this? In a custom module or on a page? The choice tag only works inside the editor to let the page author choose a value. It won't render on a public page.
Theoretically, you could get the list of names for use in a loop using a filter like this
{% set names = hubdb_table_rows(TABLE_ID)|attr('name') %}
But that doesn't currently work. I'm looking at why.
To clarify, the choice dropdown would be in the editor. So ideally I have a list of employees:
Steve
Bob
Sally
John
And they would all be set up in the database with other information about them.
Then when I go in to create a page for Steve, I could just have a choice dropdown in the editor, and could have the rest of the information from the database fill in the page. It'd give me one place to keep employee information up to date and then it could update on both the listing and employee page at the same time.
I played around with your suggestion. Looks like you can't do the filter until you call the variable. I was able to make some progress doing this:
{% set table_info = hubdb_table(XXXXXX) %} {{ table_info|attr('columns')}}
But then that spits out all of the attributes about each column (name, type, ID, options, etc.). I'm still trying to get the info in one columns (not the information about a column) and then use that to prepopulate my choice dropdown. This might be progress.
I am also trying to get this to work but i am getting an error when trying to publish the template, says it can not validate the template at this time.