CMS Development

pandapandapanda
参加者

Unique module ID to help reference multiple instances of the module in the same template

解決

I'm creating a module which requires a reference to an html ID. End users will unlikely know why they need an ID so this ideally should be auto generated.

 

It's also possible to include this module multiple times within a template, so the ID will somehow need to be unique as well.

 

What's the best solution to this?

1件の承認済みベストアンサー
JasonRosa
解決策
HubSpot Employee
HubSpot Employee

Unique module ID to help reference multiple instances of the module in the same template

解決

Hey @pandapandapanda you could use the HubL variable of {{ name }} to generate a new ID for each instance of the module on a page. I answered a post a little while back with more details here: https://community.hubspot.com/t5/CMS-Development/HubL-Any-way-to-get-the-id-of-the-module-instance/m.... Let me know if you have any questions about this after reading through that other post!

元の投稿で解決策を見る

3件の返信
JasonRosa
解決策
HubSpot Employee
HubSpot Employee

Unique module ID to help reference multiple instances of the module in the same template

解決

Hey @pandapandapanda you could use the HubL variable of {{ name }} to generate a new ID for each instance of the module on a page. I answered a post a little while back with more details here: https://community.hubspot.com/t5/CMS-Development/HubL-Any-way-to-get-the-id-of-the-module-instance/m.... Let me know if you have any questions about this after reading through that other post!

pandapandapanda
参加者

Unique module ID to help reference multiple instances of the module in the same template

解決

Thanks Jason! That's exactly what I was looking for! Is there a cheat sheet with all these codes somewhere by any chance?

0 いいね!
JasonRosa
HubSpot Employee
HubSpot Employee

Unique module ID to help reference multiple instances of the module in the same template

解決

Hey @pandapandapanda, awesome I'm happy to hear that helped! There is a brief doc on this in our designers docs here (https://designers.hubspot.com/docs/modules/reference). More specifically, the built in custom module variables can be found here (https://designers.hubspot.com/docs/modules/reference#module-variables) at the bottom of that article.