5

I am using the core service (Tridion 2013 (no SP)) to get some stats and I am experiencing a weird behavior. In the system there are multiple pages (494) using the same page template. Using the core service I run this code:

string id = "tcm:73-18028-128";

var wuFilter = new UsingItemsFilterData();

//wuFilter.IncludeLocalCopies = true;
//wuFilter.IncludeVersionsColumn = true;
wuFilter.IncludedVersions = VersionCondition.OnlyLatestAndCheckedOutVersions;
//wuFilter.BaseColumns = ListBaseColumns.Extended;

wuFilter.ItemTypes = new ItemType[]{ItemType.Page};

var xml = Tridion.GetListXml(id, wuFilter);
XNamespace ns = xml.Name.Namespace;
Debug.WriteLine("Pages Using Template "+id+":" + xml.Descendants(ns+"Item").Count());

That gives me 87 pages.

When I select such page template in the CME and do a "Where used", I also get 87.

Now, If I get all the pages in that publication and count those using the previous PT, I get 494. I used this code for this:

var filter = new RepositoryItemsFilterData ();
filter.Recursive = true;
filter.ItemTypes = new ItemType[]{ItemType.Page};

var otherXml = Tridion.GetListXml("tcm:0-73-1", filter);
XNamespace ns2 = otherXml.Name.Namespace;
int counter = 0;
foreach (XElement node in otherXml.Descendants(ns2 + "Item"))
{
    string id2 = node.Attributes("ID").FirstOrDefault().Value;
    PageData page = Tridion.Read(id2, new ReadOptions()) as PageData;
    if(page.PageTemplate.IdRef == id){
        counter++;
    }
}
Debug.WriteLine("Pages Using Template "+id+":" + counter);

Anybody experienced weird behavior with "Where Used"?

  • I got this from Alvin Reyes: "I think Mihai or someone saw something about pages that don't explicitly have a page template set--these get there page template from their structure groups" I checked, and it seems right. Isn't this a bug? – Jaime Santos Alcón Jan 15 '15 at 20:58
  • technically, your findings are correct. The link to the template is not from the page, therefore it doesn't use it. If you think that's a defect, file a ticket with support and we'll evaluate it – Nuno Linhares Jan 15 '15 at 21:07
  • 1
    Thanks Nuno, will do. You are right, the page should not show in the "Where Linked" list, but definitely in the "Where Used", since such pages "use" the template. :) – Jaime Santos Alcón Jan 15 '15 at 21:11
  • 2
    Who can tell if the page uses it? If I use PT1 on SG1, publish all the pages, switch SG1 to use PT2, and don't publish the pages - which one is actually being used? What's the definition of "used"? Etc. It's turtles all the way down. – Nuno Linhares Jan 15 '15 at 21:12
  • Great, now when I search for where I heard this originally I'll get this post. Thanks for confirming, though. :-) – Alvin Reyes Jan 15 '15 at 21:16
4

Moving some of the comments into an answer - since nobody reads comments anyway...

What you are describing is actually how the system works. The reference between the Page Template and the Structure Group is what "Where Used" will track, and not the individual pages within the Structure Group.

So, technically, what you are seeing is the correct behavior - the Page Template is used by the Structure Group and the pages - when rendered - will use this information to find the template to use. If you need to calculate which pages are currently published with a given template (which probably matches closer to your definition of "being used") then it might be easier to get this data from the Content Delivery DB if this is an option.

As to whether the current behavior is the correct one... that's a complex question, and as I mention in a comment, it challenges the current definition of "being used" altogether. If I set a Page Template in a Structure Group and never publish the pages within it - is this Page Template being used by the pages? Is it "at risk" of being used? What if I published the pages, then change the information in the Structure Group and then delete the page template? Which template is in use now by the pages?

Interesting discussion for which there is probably a valid answer - I would prefer to keep the system as is than interfering with the definition of "being used" and risk making wrong assumptions that would make it even harder to determine what templates are used where.

| improve this answer | |
  • Well, the actual reason for me doing this is to identify how many (and which ones) pages will be affected if I modify a given Page Template, which with the current design requires more than just a "Where Used" query... I also realized that if you move pages (not having been published) between SGs with different "Default Page Templates", the page adopts the PT from the SG it lives in... which is good to know (in fact, I just learnt that) – Jaime Santos Alcón Jan 16 '15 at 13:01
2

If you are interested in knowing how many pages will be affected you should use the "show which items will be published" option on the publish dialog (which you will reach by publishing the page template):

publishdialog

| improve this answer | |
  • Is there a way to retrieve this list from the Core Service? – Jaime Santos Alcón Jan 20 '15 at 16:37
  • Yes, of course. The UI is built on top of the core service – Nuno Linhares Jan 20 '15 at 18:11
  • Have a look at the ICoreService2010.ResolveItems method... – Bjørn van Dommelen Jan 21 '15 at 15:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.