I have MyDoc but I need to get the Page which contains my doc component
It seems that you're trying to
Resolve items in this TBB, i.e. determine which items would be published if you were to publish a given item. You can do that in a TBB, though I think additional clarity on the actual requirement (rather than the solution) would probably get you a better answer because I'm struggling to see why you would want to!
You can call the Resolver with a
ResolveEngine.ResolveItem(), which requires:
- An Item to Resolve
- An Instruction on how to handle the resolving
- A Publish Context (which requires a Publication Target)
For the Publication Target, there will be one in actual publishing, but not in Template Builder, so you'll have to choose one that the publication can actually publish to.
class GetPagesUsingComponent : ITemplate
public void Transform(Engine engine, Package package)
string id = "tcm:24-8238"; //Note hardcoded TCM Id
Component component = (Component) engine.GetObject(id);
PublicationTarget publicationTarget = engine.PublishingContext.PublicationTarget;
if (publicationTarget == null) //If it's Template Builder, this will be null, so...
publicationTarget = (PublicationTarget)engine.GetObject("tcm:0-5-65537");
//again, note hardcoded TCM Id - which should be a publication target the
//publication can use!
ResolveInstruction resolveInstruction = new ResolveInstruction(engine.GetSession())
IncludeChildPublications = true,
StructureResolveOption = StructureResolveOption.OnlyItems
PublishContext publishContext = new PublishContext(
List<ResolvedItem> resolvedItems = ResolveEngine.ResolveItem(component,
.Where(resolvedItem => resolvedItem.Item.Id.ItemType == ItemType.Page)
TemplatingLogger.GetLogger(this.GetType()).Debug("Found " + resolvedItems.Count);
foreach (ResolvedItem resolvedItem in resolvedItems)
resolvedItem.Item.Id + " - " + resolvedItem.Item.Title);
On our system, this outputs into the Debug log in Template Builder:
GetPagesUsingComponent: Found 2
GetPagesUsingComponent: tcm:24-8244-64 - Business travel
GetPagesUsingComponent: tcm:24-13433-64 - Business travel policy
Just to reiterate my first point: just because you can do this doesn't mean you necessarily should. Resolving is a fairly intensive database call that is run whenever something is published, and by calling it again it's being run twice. There is probably a better solution to your requirement if you could post what you're trying to achieve instead of your anticipated solution :)