CMS Development

piersg
Key Advisor

Possible to loop over multiple HubDBs in a module?

SOLVE

Is it possible to loop over, and access, the data from multiple HubDBs in a custom module?

 

For example I can do this and it returns the HubDB table id, but only the id

{% for item in module.hubdbtable %}{{item}}{% endfor %}>

However, when you do this, the id is invalid and I get the error "Table `` not found in your account."

{% for item in module.hubdbtable %}
{% set id = item %} {% set table = hubdb_table_rows(id) %} {% for row in table %} <p>{{row.name}}</p>
// ...etc {% endfor %} {% endfor %}

I'm trying to pull multiple DBs onto one page via a module. I've written JS code to do this using the HubDB API, but I want to see if it's possible with HubL.

0 Upvotes
1 Accepted solution
piersg
Solution
Key Advisor

Possible to loop over multiple HubDBs in a module?

SOLVE

If anyone was curious or comes across this, item in this case is an object (although doesn't seem like one if you output it), so you need to use dot notation. All credit and thanks to @Jsum.

{% for item in module.hubdbtable %}
  {% set table = hubdb_table_rows(item.id) %}
  {% for row in table %}
    <p>{{row.name}}</p>
      // ...etc
  {% endfor %}
{% endfor %}

 

View solution in original post

2 Replies 2
piersg
Solution
Key Advisor

Possible to loop over multiple HubDBs in a module?

SOLVE

If anyone was curious or comes across this, item in this case is an object (although doesn't seem like one if you output it), so you need to use dot notation. All credit and thanks to @Jsum.

{% for item in module.hubdbtable %}
  {% set table = hubdb_table_rows(item.id) %}
  {% for row in table %}
    <p>{{row.name}}</p>
      // ...etc
  {% endfor %}
{% endfor %}

 

sharonlicari
Community Manager
Community Manager

Possible to loop over multiple HubDBs in a module?

SOLVE

Hey @piersg        

 

Thank you for the information provided. I'll tag a few experts.    

 

Hey @SandyG1 @alyssamwilie @stefen what would you advise @piersg?      

 

Thanks 

Sharon


Did you know that the Community is available in other languages?
Join regional conversations by changing your language settings !




0 Upvotes