1

I have a website where the title of the page is defined in a page template. I would like to get this value from the component which is inside this page. How do we do that?

Right now we are using the title from the metadata. @@Page.MetaData.heading@@

5

Following on what Saurabh has already said, you will need to branch out of simple Dreamweaver templating to access the fields of the component from a PT. To do this you'll need to do a couple things. First, add the default building block "Extract Components from Page" to the page template before your DWT. Without this TBB the component presentations from the page won't be on the package used during publishing of a page. You will then need to write your own TBB to access the component presentations, placed between the above TBB and your DWT. I've taken the following sample right from the SDL documentation.

// Get the Components array. ComponentsName is a constant for the string "Components"

Item componentsItem = package.GetByName(ComponentsName);
IComponentPresentationList componentPresentations = ComponentPresentationList.FromXml(componentsItem.GetAsString());
Tridion.ContentManager.Templating.ComponentPresentation componentPresentation = componentPresentations[1];

This will give you the first component presentation. You can then retrieve the field contents and place them onto the package using something like

package.PushItem("title", package.CreateHtmlItem([[title string name]]));

to place the title contents from the component onto the package. In your DWT you can just do "@@title@@" to render out the desired content.

8

A Page has component presentations on it, and a component presentation is component plus component template. In your case, you want the component so that you can fetch Title field from it.

So, all you need to do in PT code is:

  1. Get the component presentations array on the page.
  2. Select the component presentation of your need.
  3. Get the component out of the component presentation.
  4. Get the title field value from the component.

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.