I need to retrieve the page or pages that are published and the component presentation of the page (or pages) contain a certain component. If a component exists on multiple pages, I would like to know which one is the closest to the root. How can I achieve this using queries in TOM.Net?
I’m a bit confused by your comment “this is going to be on a TBB and run at the runtime. This code won’t run at the rendering time.”
In general, TBB code runs at rendering time. And the reason why Jonathan asked for it, is because only templating and event handler code is supposed to use the TOM.NET (rather than the Core Service).
Anyways, assuming that you want to use the TOM.NET: have a look at method
IdentifiableObject.GetUsingItems in the API reference docs.
With this method, you can find the (published) Pages on which a given Component is used. Distance from the root can be determined using
What have you tried so far? I'm asking because this question is a "do my homework instead of me" type, so there is little chance that someone will write your code instead of you. Best we can do is give you some hints, and then using the API found HERE you can easily put together your own code. For debugging purposes you can attach to the Template Builder process, or do it the hard way with
- To retrieve the published pages you can use the
- To see whether a Component is used on a Page, you can either look
ComponentPresentationsof a Page, or you can use the 'where used' functionality with the
UsingItemsFilteron the relevant Component
- To find the one Page closest to the "Root", you can compare their
PublishLocationPathproperty. Or do a search by item type Page starting from the Root and going deeper each iteration