Documentation Center

Quick Guide to creating a Component Template

This Quick Guide instructs you on the fundamentals of templating by walking you through the creation of your first Component Template, based on an HTML design we provide.

Before you begin

To perform this task, you must have the core software components of SDL Tridion installed and configured. Also, the WebDAV client needs to be set up, allowing you to browse the Content Manager organizational items structure from Windows Explorer.

About this task

After completing this Quick Guide, you will be able to use the Component Template to produce Component Presentations (rendered pieces of content) that look like the one pictured below.

The Web content your Component Template will produce is in HTML 5. You can change the resources to be compatible with other versions of HTML.

Step 1: Creating a Publication and uploading resources

Create a dedicated Publication for this exercise.

Procedure

  1. In Content Manager Explorer, create a new Publication called "Quick Guide to Templating" and create a basic structure for it. You can skip this step if you already went through the Quick Guide to creating a Page Template.
  2. In Windows Explorer, download the design zip file from this location: http://sdl.dist.sdlmedia.com/vms/distribution/?o=A3485AFB-EDCE-4980-9F3E-961E0815E43D
  3. Copy the files in this zip file into the organizational items of your new Publication (accessed through WebDAV) as follows:
    1. Copy the following files from the \images\ folder in the design zip file to the /Building Blocks/System/Template Building Blocks/Design/images/ Folder in your new Publication:
      • button-search.png
      • example.jpg
      • logo.png
      • trex.jpg

      You can skip this step if you already went through the Quick Guide to creating a Page Template.

    2. Open \design.htm in the design zip file for editing, find the first section called article and copy this section to a new text file. Save the file as Article Summary Design.dwt, then save it locally.
  4. In Content Manager Explorer, navigate to /Building Blocks/System/Template Building Blocks/Design/. In that location, select the Create Ribbon tab and select New Template Building Block.
  5. In the dialog that opens, fill in Article Summary Design in the Name field.
  6. Select the Source tab, ensure that Template Type is set to Dreamweaver, and make the text box empty.
  7. Open the file Article Summary Design.dwt that you saved and copy-paste all of its contents into the text box. Then select Save and Close to commit your changes.

Step 2: Creating the Schema

Identify the editable parts of the piece of content and create a Schema with fields corresponding to those parts.

Procedure

  1. Examine the rendered piece of content for visual and other cues that identify its parts, and give them names. In our case, the following image shows which fields we are able to identify:

  2. In Content Manager Explorer, navigate to Building Blocks\System\Schemas\.
  3. In the Ribbon toolbar Create tab, select New Schema.
  4. In the dialog that opens, set Name and Description to Image and Type to Multimedia Schema.
  5. In the Available Multimedia Types area that appears, select the following items on the right and double-click them to move them to the right:
    • Gif image
    • Jpeg image
    • Png image
  6. Click Save and close to create the Multimedia Schema.
  7. In the Ribbon toolbar Create tab, select New Schema again.
  8. In the dialog that opens, set Name and Description to Article.
  9. Click the Design tab and use the Add button to create the following fields, all mandatory:
    NameTypeOther properties
    titleText(none)
    summaryTextHeight of the Text Area: 5 rows
    bodyTextHeight of the Text Area: 10 rows, Allow Rich Text Formatting
    imageMultimedia LinkAllowed Schemas: Image
    authorText(none)
    dateDate(none)
  10. Click Save and Close to save your Schema and close the dialog.

Results

You now have a Schema that defines the structure of your content as individual fields, and a Multimedia Schema that defines the types of binary content for one of those fields.

Step 3: Creating Components

Now that we have a Schema, we can create Components based on that Schema, one for each article in our design.

About this task

We first make Multimedia Components (containing the images), so that we can refer to them from our Components (containing the articles).

Procedure

  1. Decide on a set of images to use in your articles. You can use the ones included in the design files, or you can use your own (this works best if the are roughly the same dimensions as the original ones).
  2. In Content Manager Explorer, select the Building Blocks Folder in your Publication, and in the Ribbon toolbar Create tab, select New Folder to create two new Folders: Components and Multimedia Components.
  3. Navigate to Multimedia Components and in the same Create tab, select New Component > New Multimedia Component.
  4. In the dialog that opens, set Name to a descriptive name of an image you want to use, and Schema to Image.
  5. In the Component Content area that appears, select the type of image from the Multimedia Type dropdown, and select Load from Disk to navigate to, and select, the image you want to upload.
    The image appears in the dialog.
  6. Click Save and Close to save your Multimedia Component.
  7. Repeat the steps to upload more images and save them as Multimedia Components.
  8. Navigate to the Folder \Building Blocks\Components\ that you created earlier, and in the same Create tab as before, select New Component.
  9. In the dialog that opens, set Name to a descriptive name of an article you want to add to Content Manager, and Schema to Article.
  10. Fill in the text fields that appear. The Body field lets you add formatting to the text.
  11. Set a value for the Date field using the calendar control.
  12. Click the Browse icon next to the Image field and in the dialog that opens, navigate to \Building Blocks\Multimedia Components\Design\ and select one of the images you uploaded as an image to go with your article. Click Insert to use it.
  13. With all fields filled in, select Save and Close to save the Component.
  14. Repeat the steps to create more articles.

Step 4: Creating the Component Template

Using the Template Builder desktop application, create a Component Template that uses the design item you created.

Procedure

  1. In Content Manager Explorer, in the Tools Ribbon tab, select Template Builder.
    Template Builder opens.
  2. Select File > New and in the dialog that opens, navigate to Building Blocks\System\Templates\Component Templates\.
  3. Call the Template "Article Summary" and set the type to Component Template. Then click OK to create the Template and close the dialog.
  4. In the main view, in the Building Blocks panel, from the Design group, drag the Template Building Block called Article Summary Design into the middle area.
  5. In the same panel, from the Default Templates group. drag Default Finish Actions into the middle area, below Article Summary Design.
  6. In the toolbar, press Run (the button with the arrowhead pointing to the right) and in the Open Component dialog that opened, navigate to and select one of the Components you created. Click OK to close the dialog and run the Template.
  7. When the Template has run, select the item Result in the content area.
  8. In the Package panel below it, select the item with the value Output in the name column.
    The Item View panel on the right shows a preview of the rendered Component, but without the images, which are still hardcoded.
  9. Save and close your Component Template.
  10. Access Content Manager Explorer and navigate to Building Blocks\System\Templates\Component Templates\. Open the Component Template "Article Summary" in this location.
  11. In the dialog, that opens, select the Linked Schemas tab.
  12. In the left list called Available Schemas, double-click Article to move it the list on the right called Linked Schemas.
  13. Save and close the Component Template

Results

You now have a Component Template, but it renders the contents of your original article as hardcoded contents. Obviously, the contents of the fields are not part of your design, but their look-and-feel and layout are.

Step 5: Replacing hard-coded field contents with code

To replace the hard-coded field contents with code that dynamically retrieves the fields' contents from the Component being rendered, replace the contents with code.

Procedure

  1. In Content Manager Explorer, navigate to the Folder Building Blocks\System\Templates\Template Building Blocks\Design\ and open the Template Building Block called "Article Summary Design" in this location.
  2. In the dialog that opens, select the Source tab.
  3. Replace the contents of the Source tab with the following:
    <article class="wrap wide" xmlns:tridion="http://www.tridion.com/ContentManager/5.0">
    
      @@FieldStartMarker("Component.Fields.image")@@
        @@FieldValueStartMarker(0)@@
          <img src="${Component.Fields.image}" tridion:type="Multimedia" alt="image" />
        @@FieldValueEndMarker()@@
      @@FieldEndMarker()@@
    
      <h2 class="title">
        @@FieldStartMarker("Component.Fields.title")@@
          @@FieldValueStartMarker(0)@@
            @@GetFieldValue("title", 0)@@
          @@FieldValueEndMarker()@@
        @@FieldEndMarker()@@
      </h2>
      <p class="info">Posted by @@FieldStartMarker("Component.Fields.author")@@
        @@FieldValueStartMarker(0)@@
          @@GetFieldValue("author", 0)@@
        @@FieldValueEndMarker()@@ 
      @@FieldEndMarker()@@ - @@FieldStartMarker("Component.Fields.date")@@
        @@FieldValueStartMarker(0)@@
          @@GetFieldValue("date", 0)@@
        @@FieldValueEndMarker()@@
      @@FieldEndMarker()@@</p>
      <p>
        @@FieldStartMarker("Component.fields.summary")@@
          @@FieldValueStartMarker(0)@@
            @@GetFieldValue("summary", 0)@@
          @@FieldValueEndMarker()@@
        @@FieldEndMarker()@@
      </p>
      <p class="more"><a tridion:href="@@Component.ID@@" tridion:textonfail="false">Read more &raquo;</a></p>
    </article>

    This code render each of the fields of the Component it is rendering except for Body. This is because this Template Building Block is intended to render a summary only of the article.

  4. Save and close your Template Building Block.