CMS Development

xyboox
Participant

Populate "choice" tag at runtime

Hello,

 

I have this scenario: we have a firebase database with some data ( let's say some articles ). We'd like to use a "choice" tag or field ( although with field I believe is not possible ) for allowing an editor to select which set of data ( article ) to be used in a template for creating a webpage. For example: we would have a dropdown selector ( generated by a choice tag ) with article titles as options. When the editor selects one of those, the template would use selected set of data.

 

Is this possible? I tried this code in <head> of the template:

 

{% require_js %}
<script>
window.choices = ... // async request using fetch to grab and properly format for "choices" the article titles from firebase. An example of the variable content would be: "First article title, Second article title"
</script>
{% end_require_js %}

{% choice "select_article" label="Select Article", choices="{{window.choices}}" export_to_template_context=true %}

 

 

but since choice tag is rendered by hubspot systems server side ( and so before the page reaches the browser ), obviously window.choices = null.

Would this be a use case for a serverless function? Not sure if that can be executed server side before page being sent to the client.

 

Thanks!

0 Upvotes
2 Replies 2
stefen
Key Advisor | Partner
Key Advisor | Partner

Populate "choice" tag at runtime

@Jaycee_Lewis @xyboox have you considered migrating that content to HubSpot's HubDB? You could also leave the data there but use a serverless function to sync that data to HubDB.

Stefen Phelps, Community Champion, Kelp Web Developer
Jaycee_Lewis
Community Manager
Community Manager

Populate "choice" tag at runtime

Hi, @xyboox 👋 Thanks for including those details. Hey, @stefen @Teun @louischausse, do you have any insight you can share with @xyboox?

 

Thank you very much! — Jaycee

linkedin

Jaycee Lewis

Developer Community Manager

Community | HubSpot

0 Upvotes