Reputation: 93
I would like my Apostrophe projects to reuse some widgets down the page hierarchy, similar to how a header, footer or vertical navigation work, especially the latter. However, I would like to avoid using data.global
as I want that content to appear only in the subtree of the page I'm adding it, not in all pages. For example, that would allow me to define "sections" in the website with some specific header/footer in common, regardless of the template.
Another use case would be the possibility of creating multisite projects without the apostrophe-multisite
module, which works great if you don't want to share any content accross sites, but in some of my use cases I need to share content like pieces and images (e.g., for sponsors, or linking them without an absolute URL but with a join) accros many sites.
Could I achieve that by, in a template area (or wherever, I really have no clue), querying that area in the ancestors and including their content before the one in the actual page's area? If so, does it make sense from an Apostrophe point of view or will the performance be very affected by such recursive querying?
Upvotes: 0
Views: 70
Reputation: 7572
Yes, you can do what you're asking.
By default, data.page._ancestors
does not call widget loaders for areas in ancestors, for performance reasons, just as you suspected.
However, you can opt into this:
// in lib/modules/apostrophe-pages/index.js of your own project
// (do NOT modify it in node_modules/apostrophe!)
module.exports = {
// other configuration here, then...
filters: {
ancestors: {
children: {
areas: [ 'thumbnail' ]
}
}
}
};
This will call widget loaders specifically for the area called thumbnail
for each ancestor, but not any others. This is much better for performance than setting areas: true
, but you could do that too if you really wanted to wait!
Upvotes: 1