本文整理汇总了C#中Package.CreateStringItem方法的典型用法代码示例。如果您正苦于以下问题:C# Package.CreateStringItem方法的具体用法?C# Package.CreateStringItem怎么用?C# Package.CreateStringItem使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Package
的用法示例。
在下文中一共展示了Package.CreateStringItem方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Transform
public void Transform(Engine engine, Package package)
{
if (package.GetByName(Package.PageName) == null) return;
Page page = (Page)engine.GetObject(package.GetByName(Package.PageName));
bool hasHeader = false;
bool hasFooter = false;
foreach (CP cp in page.ComponentPresentations)
{
if (cp.ComponentTemplate.Title.ToLower().Contains("header")) hasHeader = true;
if (cp.ComponentTemplate.Title.ToLower().Contains("footer")) hasFooter = true;
}
if (!hasHeader)
{
ComponentTemplate headerCt = (ComponentTemplate)engine.GetObject(page.ContextRepository.RootFolder.WebDavUrl + HeaderComponentTemplateUrl);
Component header = (Component)engine.GetObject(page.ContextRepository.RootFolder.WebDavUrl + HeaderComponentUrl);
package.PushItem("headerCP", package.CreateStringItem(ContentType.Html, string.Format("<tcdl:ComponentPresentation type=\"Dynamic\" componentURI=\"{0}\" templateURI=\"{1}\" />", header.Id, headerCt.Id)));
}
if (!hasFooter)
{
ComponentTemplate footerCt = (ComponentTemplate)engine.GetObject(page.ContextRepository.RootFolder.WebDavUrl + FooterComponentTemplateUrl);
Component footer = (Component)engine.GetObject(page.ContextRepository.RootFolder.WebDavUrl + FooterComponentUrl);
package.PushItem("footerCP", package.CreateStringItem(ContentType.Html, string.Format("<tcdl:ComponentPresentation type=\"Dynamic\" componentURI=\"{0}\" templateURI=\"{1}\" />", footer.Id, footerCt.Id)));
}
}
示例2: Transform
public void Transform(Engine engine, Package package)
{
TemplatingLogger log = TemplatingLogger.GetLogger(GetType());
RepositoryLocalObject context;
if (package.GetByName(Package.PageName) != null)
{
context = (RepositoryLocalObject)engine.GetObject(package.GetByName(Package.PageName));
log.Debug("Setting context to page with ID " + context.Id);
}
else
{
log.Info("This template building block should only run on a page. Exiting.");
return;
}
if (!(context is Page)) return;
Page page = (Page)context;
package.PushItem(SiteEditPageContext, package.CreateStringItem(ContentType.Text, page.OwningRepository.Id));
package.PushItem(SiteEditPublishContext, package.CreateStringItem(ContentType.Text, page.ContextRepository.Id));
if (page.ComponentPresentations.Count <= 0) return;
Component component = page.ComponentPresentations[0].Component;
package.PushItem(SiteEditComponentContext, package.CreateStringItem(ContentType.Text, component.OwningRepository.Id));
}
示例3: Transform
public void Transform(Engine engine, Package package)
{
TcmUri templateId = engine.PublishingContext.ResolvedItem.Template.Id;
if (templateId.ItemType != ItemType.ComponentTemplate) return;
Item item = package.CreateStringItem(ContentType.Text, templateId);
package.PushItem("ComponentTemplateId", item);
package.PushItem("RenderMode", package.CreateStringItem(ContentType.Text, engine.RenderMode.ToString()));
}
示例4: Transform
public override void Transform(Engine engine, Package package)
{
Initialize(engine, package);
Component comp = GetComponent();
if (IsPageTemplate() || comp == null)
{
Logger.Error("No Component found (is this a Page Template?)");
return;
}
Item outputItem = package.GetByName(Package.OutputName);
if (outputItem == null)
{
Logger.Error("No Output package item found (is this TBB placed at the end?)");
return;
}
_metaFieldNames = (package.GetValue("multimediaLinkAttributes") ?? String.Empty).Split(',').Select(s => s.Trim()).ToList();
// resolve rich text fields
string output = outputItem.GetAsString();
package.Remove(outputItem);
if (output.StartsWith("<"))
{
Logger.Debug("Content is XML");
//XML - only for backwards compatibility
package.PushItem(Package.OutputName, package.CreateXmlDocumentItem(ContentType.Xml, ResolveXmlContent(output)));
}
else
{
Logger.Debug("Content is JSON");
//JSON
package.PushItem(Package.OutputName, package.CreateStringItem(ContentType.Text, ResolveJsonContent(output)));
}
}
示例5: Transform
public void Transform(Engine engine, Package package)
{
if (package.GetByName(Package.PageName) == null) return;
comm.Page page = (comm.Page)engine.GetObject(package.GetByName(Package.PageName));
Dictionary<string, List<ComponentPresentation>> lists = new Dictionary<string, List<ComponentPresentation>>();
string matchTokens = package.GetValue("ComponentTemplateTitleMatchTokens");
if (!String.IsNullOrEmpty(matchTokens))
{
foreach (string token in matchTokens.Split(','))
{
_matchTokens.Add(token.Trim());
}
}
foreach (comm.ComponentPresentation cp in page.ComponentPresentations)
{
string ct = GetPresentationType(cp.ComponentTemplate.Title);
if (!lists.ContainsKey(ct))
lists.Add(ct, new List<ComponentPresentation>());
lists[ct].Add(new ComponentPresentation(cp.Component.Id, cp.ComponentTemplate.Id));
}
foreach (string token in lists.Keys)
{
Item item = package.CreateStringItem(ContentType.ComponentArray, ComponentPresentationList.ToXml(lists[token]));
package.PushItem(token + "Components", item);
}
}
示例6: Main
static void Main(string[] args)
{
ITemplate tbb = new RegexReplace();
Session session = new Session();
Console.WriteLine(session.GetObject("tcm:4-847").Title);
using (UnittestingTemplatingRenderer engine = new UnittestingTemplatingRenderer("tcm:4-847", "tcm:4-64-32"))
{
Package package = new Package(engine);
package.PushItem(Package.OutputName, package.CreateStringItem(ContentType.Text, "Tridion Developer Summit 2013"));
package.PushItem("tp_find", package.CreateStringItem(ContentType.Text, "2013"));
package.PushItem("tp_replace", package.CreateStringItem(ContentType.Text, "2014"));
tbb.Transform(engine, package);
string output = package.GetValue(Package.OutputName);
}
Console.ReadLine();
}
示例7: Transform
public override void Transform(Engine engine, Package package)
{
Engine = engine;
Package = package;
var c = IsPageTemplate() ? GetPage().ComponentPresentations[0].Component : GetComponent();
XmlDocument resourceDoc = null;
resourceDoc = new XmlDocument();
resourceDoc.LoadXml("<root/>");
var fields = new ItemFields(c.Content, c.Schema);
var sourceField = fields["resource"] as EmbeddedSchemaField;
foreach (var innerField in sourceField.Values)
{
var key = innerField["key"] as TextField;
var value = innerField["value"] as TextField;
var data = resourceDoc.CreateElement("data");
data.SetAttribute("name", key.Value);
var v = resourceDoc.CreateElement("value");
v.InnerText = value.Value;
data.AppendChild(v);
resourceDoc.DocumentElement.AppendChild(data);
}
package.PushItem(Package.OutputName, package.CreateStringItem(ContentType.Xml, resourceDoc.OuterXml));
}
示例8: Transform
public void Transform(Engine engine, Package package)
{
TemplatingLogger log = TemplatingLogger.GetLogger(GetType());
if (package.GetByName(Package.PageName) == null)
{
log.Info("Do not use this template building block in Component Templates");
return;
}
Page page = (Page)engine.GetObject(package.GetByName(Package.PageName));
string output;
if (page.Title.ToLower().Contains("index"))
output = StripNumbersFromTitle(page.OrganizationalItem.Title);
else
{
output = GetLinkToSgIndexPage((StructureGroup)page.OrganizationalItem, engine.GetSession()) + Separator + StripNumbersFromTitle(page.Title);
}
foreach (OrganizationalItem parent in page.OrganizationalItem.GetAncestors())
{
output = GetLinkToSgIndexPage((StructureGroup)parent, engine.GetSession()) + Separator + output;
}
package.PushItem("breadcrumb", package.CreateStringItem(ContentType.Html, output));
}
示例9: Transform
public void Transform(Engine engine, Package package)
{
Component component = (Component)engine.GetObject(package.GetByName(Package.ComponentName));
ItemFields fields = new ItemFields(component.Content, component.Schema);
TextField code = (TextField)fields["Code"];
package.PushItem(Package.OutputName, package.CreateStringItem(ContentType.Html, code.Value));
}
示例10: Transform
public void Transform(Engine engine, Package package)
{
RepositoryLocalObject context;
if (package.GetByName(Package.ComponentName) != null)
{
context = (RepositoryLocalObject)engine.GetObject(package.GetByName(Package.ComponentName));
}
else if (package.GetByName(Package.PageName) != null)
{
context = (RepositoryLocalObject)engine.GetObject(package.GetByName(Package.PageName));
}
else
{
throw new Exception("Could not determine context from package. Did not find page or component in package");
}
Repository contextPublication = context.ContextRepository;
if (contextPublication.Metadata == null) return;
ItemFields metadata = new ItemFields(contextPublication.Metadata, contextPublication.MetadataSchema);
ComponentLinkField configuration = (ComponentLinkField)metadata["SiteConfiguration"];
foreach (Component c in configuration.Values)
{
ItemFields content = new ItemFields(c.Content, c.Schema);
foreach (ItemField field in content)
{
var textField = field as TextField;
if (textField != null)
{
package.PushItem(textField.Name, package.CreateStringItem(ContentType.Text, textField.Value));
}
}
}
}
示例11: Transform
public void Transform(Engine engine, Package package)
{
// do NOT execute this logic when we are actually publishing! (similair for fast track publishing)
if (engine.RenderMode == RenderMode.Publish || (engine.PublishingContext.PublicationTarget != null && !Tcm.TcmUri.IsNullOrUriNull(engine.PublishingContext.PublicationTarget.Id)))
{
return;
}
Item outputItem = package.GetByName("Output");
String inputValue = package.GetValue("Output");
if (string.IsNullOrEmpty(inputValue))
{
log.Warning("Could not find 'Output' in the package, nothing to preview");
return;
}
// read staging url from configuration
string stagingUrl = TridionConfigurationManager.GetInstance(engine, package).AppSettings["StagingUrl"];
string outputValue = HttpPost(stagingUrl, inputValue);
if (string.IsNullOrEmpty(outputValue))
{
outputValue = "<h2>There was an error while generating the preview.</h2>";
}
// replace the Output item in the package
package.Remove(outputItem);
package.PushItem("Output", package.CreateStringItem(ContentType.Html, outputValue));
}
示例12: Transform
public void Transform(Engine engine, Package package)
{
Component c = (Component)engine.GetObject(package.GetByName(Package.ComponentName));
XmlElement xdoc = c.Content;
package.PushItem(Package.OutputName, package.CreateStringItem(ContentType.Text, JsonConvert.SerializeXmlNode(xdoc)));
}
示例13: Transform
public void Transform(Engine engine, Package package)
{
const string componentTemplateWebdavUrl = "/System/Component%20Templates/Promo%20Content.tctcmp";
if (package.GetByName(Package.PageName) == null) return;
Page page = (Page)engine.GetObject(package.GetByName(Package.PageName));
ComponentTemplate promoCt = (ComponentTemplate)engine.GetObject(page.ContextRepository.RootFolder.WebDavUrl + componentTemplateWebdavUrl);
package.PushItem("promoCtId", package.CreateStringItem(ContentType.Text, promoCt.Id));
}
示例14: Transform
public void Transform(Engine engine, Package p)
{
Component component = (Component)engine.GetObject(p.GetByName(Package.ComponentName));
ItemFields fields = new ItemFields(component.Content, component.Schema);
SingleLineTextField field = (SingleLineTextField) fields["ArticleTitle"];
p.PushItem("AsHtml", p.CreateHtmlItem(System.Security.SecurityElement.Escape(field.Value)));
p.PushItem("AsText", p.CreateStringItem(ContentType.Text, System.Security.SecurityElement.Escape(field.Value)));
}
示例15: Transform
public void Transform(Engine engine, Package package)
{
Component component = (Component)engine.GetObject(package.GetByName(Package.ComponentName));
package.PushItem(package.CreateMultimediaItem(component.Id));
if (package.GetByName(Package.OutputName) == null)
{
Item output = package.CreateStringItem(ContentType.Text, string.Empty);
package.PushItem(Package.OutputName, output);
}
}