Take the 2-minute tour ×
Tridion Stack Exchange is a question and answer site for Tridion developers and administrators. It's 100% free, no registration required.

What I need is to have the Publication Target of a current Page.

With the following code I get the Publication Target where the Page is published, but now I need to ensure that this Publication Target is the same as the Publication Target where the Page is publishing to.

ICollection<PublishInfo> publishInfo = PublishEngine.GetPublishInfo(page);
foreach (PublishInfo info in publishInfo)
{
    info.PublicationTarget.Id
}

I'm trying to avoid the situation that if you publish a Page from the same CMS into Staging and Live and you are showing the Pages just if they are published or not. Also Pages published on Staging will appear in Live.

Thanks in advance

share|improve this question
    
What exactly do you mean with "the Publication Target were the Page is"? Also where are you using this code, is it at render time in a Template and what is it exactly for then? –  Bart Koopman Dec 17 '13 at 9:09
    
What I mean is that if you are publishing a page to Live I need to know that the live Publication Target, but if I'm publishing to staging I need the Publication Target of staging. –  Tomé Dec 17 '13 at 9:12
add comment

1 Answer

up vote 9 down vote accepted

In an Assembly Template Building Block you can determine the RenderMode and PublishingContext via the engine.

But before checking what Publication Target the current item is being published to, you need to know if you are actually being published, or if the render action of the Template is just a preview.

if (engine.RenderMode == RenderMode.Publish)
{
    PublicationTarget target = engine.PublishingContext.PublicationTarget;
}

From here onwards you can use target.Id or target.Title to check if it is your staging or live target that your item is being published to.

share|improve this answer
    
Hello Bart Koopman. Thanks for the quick answer. I tested it and it looks that works when I publish the page but I get an error with Template Builder, what is a pity because as you may now it is really usefull to debug Component Templates. Thanks –  Tomé Dec 17 '13 at 10:19
1  
What error do you get in the Template Builder, the Template Builder should never pass the condition engine.RenderMode == RenderMode.Publish –  Bart Koopman Dec 17 '13 at 10:24
    
Yes you are right. The problem is that I was trying to publish in the Template Builder debug log the Publication Target Id _log.Debug("Publication Target Id: " + this.engine.PublishingContext.PublicationTarget); So that's why I got the error. So there is any way to use this.engine.PublishingContext.PublicationTarget; without being in publishing time? Really thanks in advance Bart –  Tomé Dec 17 '13 at 10:29
1  
Since the Template Builder is rendering, there is no Publication Target, so you can obviously NOT use engine.PublishingContext.PublicationTarget, if you want to debug this code, you need to attach to the publisher service, and debug when actually publishing –  Bart Koopman Dec 17 '13 at 10:43
    
Ok, Bart. Thanks for all your comments. It was really usefull –  Tomé Dec 17 '13 at 10:47
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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