Access custom module data on non layout pages

I may have the terminology wrong but I want to be able to access a custom module data field on a standard logged in members page. Is is possible to do something like this at the top of the page:

{% component source: “Members”, type: “module_of_member” %}
and then within the page content just access {{members.id}} from that custom field?

This is seperate to the normal custom module layout pages.

Yes. This is where Liquid Collections (via the collectionVariable) come into play:
https://docs.treepl.co/component-types/module-custom-modules#secAccessData

So in this case you’d add the collectionVariable to your module component tag:

{% component source: “Members”, type: “module_of_member”, collectionVariable: "myMemberData" %}

Then you can access {{myMemberData.items}} anywhere below the component.

NOTE: Modules always output an array of items even if there is only one item. So if you just want to render one piece of data somewhere you still need to loop through the array with a Liquid forloop, or access the item directly using its index, eg:

{{myMemberData.items[0].id}}

(the [0] references the first item via a zero based index)

See the documentation link above for more examples of this.

2 Likes

Thanks Adam - I thought there would be a way. I’ll have a look through the documentation.