CMS Development

miramar
Membre

HUBL not rendering array in choice selector

Résolue

On our instance of HUBL we use an array and a choice selector to be able to create a 'repeater' style element where you are able to select the number of times a block repeats. The code is as follows: 

hubl-issue-2.png

Until Friday this code worked as expected, showing numbers 1 to 8 in the dropdown when editing a Hubspot page. On Friday however this functionality has stopped working and the dropdown now just shows 1 option: "{{ text_image_rows }}":

hubl-issue-1.png

I contacted Hubspot Support and they were unable to offer me any reason as to why this may be happening - or even if it was a bug or an intended change. Could anyone provide some more information on this as our website is largely built around this repeater concept.

 

Thanks

 

 

 

0 Votes
1 Solution acceptée
miramar
Solution
Membre

HUBL not rendering array in choice selector

Résolue

As of this morning it appears that this issue has been fixed and it now works as expected, so I guess it was a bug. 

Voir la solution dans l'envoi d'origine

0 Votes
5 Réponses
Stephanie-OG
Conseiller clé

HUBL not rendering array in choice selector

Résolue

Hi there!

 

You could always have the choices set directly in the choice module, like this: 

 

{% choice "number_of_rows" label="Number of text-image rows", choices="1, 2, 3, 4, 5, 6, 7, 8", export_to_template_context=True %}

But if you'd prefer to set the variable first, I'd remove the quotation marks, like this: 

 

{% set text_image_rows = [1, 2, 3, 4, 5, 6, 7, 8] %}
{% choice "number_of_rows" label="Test", choices={{text_image_rows}}, export_to_template_context=True %}

 

I hope that helps!

 


Stephanie O'Gay Garcia

HubSpot CMS Design & Development

Website | Contact

 

If this helped, please mark it as the solution to your question, thanks!

miramar
Membre

HUBL not rendering array in choice selector

Résolue

Hi Stephanie, thanks for getting back to me!

I do still want to use a variable as this variable can sometimes be used in multiple places within a template. 

 

It seems to work when removing the quotation marks so thank you for providing that solution. It definitely has worked for years with them so must have been a recent change. Do you know why this has changed and if there is any chance it will change back? As mentioned we use this functionality very heavily across our website so updating it everywhere will take a lot of time.

 

Thanks

EDIT:

After doing some further testing it seems that although this does cause the options to render in the dropdown it stops the variable from being exported to the template context for use in other places, and if I place the export_in_template_context attribute before the choices attribute in the HUBL tag then it stops rendering the options again.

0 Votes
Stephanie-OG
Conseiller clé

HUBL not rendering array in choice selector

Résolue

I'm not sure I've ever used quotation marks so I don't know if it was that way in the past. 

 

I'm not aware of any product changes but you could always ask in the Developer Slack - a lot of the HubSpot team hang out there and might know more. 

 


Stephanie O'Gay Garcia

HubSpot CMS Design & Development

Website | Contact

 

If this helped, please mark it as the solution to your question, thanks!

0 Votes
miramar
Membre

HUBL not rendering array in choice selector

Résolue

Hi Stephanie, not sure if you saw my edit on my last post but I jumped the gun a little on my reply and your solution unfortuantely doesn't quite solve my issue. Here is my edit again to explain why:

After doing some further testing it seems that although this does cause the options to render in the dropdown it stops the variable from being exported to the template context for use in other places, and if I place the export_in_template_context attribute before the choices attribute in the HUBL tag then it stops rendering the options again.

Do you know if there is any way I can edit the code so that it will export the choice variable to the template context?

 

Thanks

0 Votes
miramar
Solution
Membre

HUBL not rendering array in choice selector

Résolue

As of this morning it appears that this issue has been fixed and it now works as expected, so I guess it was a bug. 

0 Votes