Documentation Center

Package

A package contains the content to publish at some stage in the template processing. Initially, a package being processed by a Page Template contains a Page item and a package for a Component Template contains a Component item. The final output of a Page Template or Component Template must contain an Output variable that contains the content to publish.

Item types in package
The items in a package can have one of several types defined in the ContentType class. You can set the content type when you add an item to a package, and later retrieve all items of a certain content type.
On a more basic level, package items have a base type of: String, (binary) stream, or XML document. The Package class defines a set of methods to create an item of each of these base types to add to the package as well as methods for creating items of certain frequently-used types, such as HTML items, items that contain the contents of a Multimedia Component, and so on.
Item names in package
The names of items in a package do not have to be unique. You can create multiple items with the same name in the package and use a stack mechanism (commonly known as Last In, First Out, or LIFO) to distinguish between them. You add an item to package using the PushItem method, making it the first item in the package with that name. All subsequent methods you call that refer to a named item, such as GetByName and Remove, always return the first item in the package with that name; that is, the item you last pushed onto the package. By calling Remove, you pop the item off the stack.
Having non-unique item names and the push-pop mechanism allow you to temporarily add items to the package during processing and remove them again when you are done with them.
EvaluateExpression
A Package has an EvaluateExpression method which takes any Templating Expression as a (String) parameter and returns the result of the evaluation. The following example demonstrates how EvaluateExpression is used:
public void Transform(Engine engine, Package package)
{
	// Get the field's value.
	string fieldProductLink = package.EvaluateExpression("Component.Fields.ProductLink");
	package.PushItem("fieldProductLink", package.CreateStringItem(ContentType.Text, fieldProductLink));
}