简体   繁体   English

Tridion 2009 - 从组件模板发布另一个组件

[英]Tridion 2009 - Publish another Component from a Component Template

First, the overall description: 一,整体说明:

There are two Component Templates, NewsArticle and NewsList. 有两个组件模板,NewsArticle和NewsList。 NewsArticle is a Dreamweaver Template, and is used to display the content of a news article. NewsArticle是一个Dreamweaver模板,用于显示新闻文章的内容。 NewsList is an xml file that contains aggregated information about all of the news articles. NewsList是一个xml文件,其中包含有关所有新闻文章的汇总信息。

Currently, a content author must publish the news article, and then re-publish the newslist to regenerate the xml. 目前,内容作者必须发布新闻文章,然后重新发布新闻列表以重新生成xml。

Problem: 问题:

I have been tasked with having the publish of a news article also regenerate and publish the newslist. 我的任务是发布新闻文章也重新生成并发布新闻列表。 Through C#, I am able to retrieve the content of the newslist component, generate the updated xml from the news article, and merge it into the xml from the newslist. 通过C#,我能够检索新闻列表组件的内容,从新闻文章生成更新的xml,并将其从新闻列表合并到xml中。 I am running into trouble getting the newslist to publish. 我在发布新闻列表时遇到了麻烦。

I have limited access to documentation, but from what I do have, I believe using the static PublishEngine.Publish method will allow me to do what I need. 我对文档的访问权限有限,但据我所知,我相信使用静态PublishEngine.Publish方法可以让我做我需要的。 I believe the first parameter (items) is just a list that contains my updated newslist, and the second parameter is a new PublishInstruction with the RenderInstruction.RenderMode set to Publish. 我相信第一个参数(items)只是一个包含我更新的新闻列表的列表,第二个参数是一个新的PublishInstruction,RenderInstruction.RenderMode设置为Publish。 I am a little lost on what the publicationTargets should be. 我对pubTgets应该是什么感到有点迷茫。

Am I on the right track? 我是在正确的轨道上吗? If so, any help with the Publish method call is appreciated, and if not, any suggestions? 如果是这样,感谢发布方法调用的任何帮助,如果没有,任何建议?

Like Quirijn suggested, a broker query is the cleanest approach. 像Quirijn建议的那样,经纪人查询是最干净的方法。

In a situation if a broker isn't available (ie static publishing model only) I usually generate the newslist XML from a TBB that adds the XML as a binary, rather than kicking off publishing of another component or page. 如果代理不可用(即仅静态发布模型),我通常会从TBB生成新闻列表XML,将XML添加为二进制文件,而不是启动另一个组件或页面的发布。 You can do this by calling this method in your C# TBB: 您可以通过在C#TBB中调用此方法来执行此操作:

engine.PublishingContext.RenderedItem.AddBinary(
  Stream yourXmlContentConvertedToMemoryStream, 
  string filename, 
  StructureGroup location, 
  string variantId, 
  string mimeType)

Make the variantId unique per the newslist XML file that you create, so that different components can overwrite/update the same file. 根据您创建的新闻列表XML文件使variantId唯一,以便不同的组件可以覆盖/更新同一文件。

Better yet, do this in a Page Template rather than Component Template so that the news list is generated once per page, rather than per component (if you have multiple articles per page). 更好的是,在页面模板而不是组件模板中执行此操作,以便每页生成一次新闻列表,而不是每个组件(如果每页有多篇文章)。

You are on the right tracks here with the engine.Publish() method: 你在这里使用engine.Publish()方法在正确的轨道上:

PublishEngine.Publish(
    new IdentifiableObject[] { linkedComponent },
    engine.PublishingContext.PublishInstruction,
     new List() { engine.PublishingContext.PublicationTarget });

You can just reuse the PublishInstruction and Target from the current context of your template. 您可以从模板的当前上下文中重用PublishInstruction和Target。 This sample shows a Component, but it should work in a page too. 此示例显示了一个Component,但它也应该在页面中工作。

One thing to keep in mind is that this is not possible in SDL Tridion 2011 SP1, as the publish action is not allowed out of the box due to security restrictions. 需要记住的一件事是,这在SDL Tridion 2011 SP1中是不可能的,因为出于安全限制,不允许发布操作开箱即用。 I have an article about this here http://www.tridiondeveloper.com/the-story-of-sdl-tridion-2011-custom-resolver-and-the-allowwriteoperationsintemplates-attribute 我在这里有一篇关于此的文章http://www.tridiondeveloper.com/the-story-of-sdl-tridion-2011-custom-resolver-and-the-allowwriteoperationsintemplates-attribute

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM