11

When publishing a component, it publishes the component against its dynamic templates and puts them in the Broker database. This is what I want. But next to the dynamic templates, it also publishes the pages where the component is used.

I don't want the pages to be published. How can I avoid that?

I implemented the event system to set IncludeComponentLinks to false:

EventSystem.Subscribe<Component, PublishEventArgs>(OnComponentPublishPre, EventPhases.Initiated);

args.PublishInstruction.ResolveInstruction.IncludeComponentLinks = false;

I hoped this code would avoid publishing related pages, but it isn't working like expected.

Does somebody have suggestions on how to fix my issue?

  • It should only publish the pages where the component is added "statically." If added to pages as DCPs, the pages shouldn't republish. – Alvin Reyes May 25 '13 at 2:54
14

Be careful here - you are seriously changing the default behaviour of Tridion - the ability to republish all pages where a component is used by publishing the component is very useful for editors who may not know where a component is used, but want to make sure that it is up to date all over their website. Why is it that you do not want the pages to be published?

If you do want to implement this, the following basic code example gives you a start point. You need to create a .NET assembly (signed with a strong name key) containing a Custom Resolver (implement the IResolver interface) , put it in the GAC on all CM and Publisher servers, and update your /config/Tridion.ContentManager.config (make a backup first!) Look for the element in the element and update the entry for components as follows:

<add itemType="Tridion.ContentManager.ContentManagement.Component">
    <resolvers>
      <add type="Tridion.ContentManager.Publishing.Resolving.ComponentResolver" assembly="Tridion.ContentManager.Publishing, Version=6.1.0.0996, Culture=neutral, PublicKeyToken=360aac4d3354074b" />
    <add type="Example.Resolving.ComponentResolver" assembly="Example.Resolving, Version=1.0.0.0, Culture=neutral, PublicKeyToken=239a69fd0ef6bf5d" />
    </resolvers>
</add>

Here is the .NET code: basically it goes through the list of what the default resolver already resolved, and removes the pages. Note that this will happen system wide - you may want to restrict your 'special' behaviour to a particular publication, or even component schema.

using Tridion.ContentManager.Publishing.Resolving;
using Tridion.ContentManager;
using Tridion.ContentManager.Publishing;
using System.Collections.Generic;
using Tridion.ContentManager.ContentManagement;
using Tridion.ContentManager.CommunicationManagement;

namespace Example.Resolving
{
    public class ComponentResolver : IResolver
    {
        public void Resolve(IdentifiableObject item, ResolveInstruction instruction, PublishContext context, Tridion.Collections.ISet<ResolvedItem> resolvedItems)
        {
            if (!(item is Component))
            {
                return;
            }
            else
            {
                List<ResolvedItem> tempItems = new List<ResolvedItem>();
                foreach (ResolvedItem resolvedItem in resolvedItems)
                {
                    if (!(resolvedItem.Item is Page))
                    {
                        tempItems.Add(resolvedItem);
                    }
                }
                resolvedItems.Clear();
                foreach (ResolvedItem resolvedItem in tempItems)
                {
                    resolvedItems.Add(resolvedItem);
                }
            }
        }
    }
}
7

Judging by the tags you used, it looks like you already thought about using a custom resolver for this. Have you actually tried using one?

I would normally handle this with a custom resolver, but the event system approach should have worked anyway, maybe there's something else going on there.

There's plenty of examples on custom resolvers out there.

2

In addition to event system code or custom resolvers, we have four basic approaches for publishing CPs.

  • Dynamic component presentations
  • Embedded static component presentations
  • Embedded dynamic component presentations
  • (Publishing binaries via templates, not so applicable here)

I describe the first three in this post (it's not just DCPs versus pages).

To avoid publishing the pages a component is used on, you can add the component to pages with "dynamic" templates. These templates would have the Component Presentations based on... option set to Published as a Dynamic Component. The Allow on Page Using Dynamic Assembly must also be checked.

You could also use the same approach to add DCPs to pages via a template in case you wanted to revisit your content model.

For reference, also see this SO question and answers or SDL Live Content (requires login).

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.