Book Image

TYPO3 4.3 Multimedia Cookbook

Book Image

TYPO3 4.3 Multimedia Cookbook

Overview of this book

TYPO3 is one of the world's leading open source content management systems, written in PHP, which can be used to create and customize your web site. Along with text content, you can display high quality images, audio, and video to your site's visitors by using TYPO3. It is essential to manage various types of multimedia files in content management systems for both editors and the users on the frontend of the site.The book gives you a step-by-step process for organizing an effective multimedia system. It also gives solutions to commonly encountered problems, and offers a variety of tools for dealing with multimedia content. The author's experience in large-scale systems enables him to share his effective solutions to these problems.If you choose to work through all the recipes from the beginning, you will start by setting up a basic web site set up, aimed at future expansion and scalability. Next, you will cover the basics of digital asset management—a major topic important in all enterprises. You can organize user groups because next you will be creating accounts for users and assigning permissions. Then you will jump into metadata—text information describing the multimedia objects—and learn how it can be manipulated in TYPO3. You will embed multimedia on your site when you have read the various methods for embedding mentioned in this book. Before you finish the book you will learn about some advanced topics, such as external API integrations and process automation.
Table of Contents (13 chapters)
TYPO3 4.3 Multimedia Cookbook
Credits
About the Author
About the Reviewers
Preface

Creating a template for a site


Our goal is to have a website for people to visit, and as such that website needs a frontend template where content will be displayed (TYPO3 can be used for other applications as well).

Getting ready

We will create a very basic template, which will allow us to see the results of the work in TYPO3 on the page. On a real project, you will probably be given a template by a designer.

Make sure to create a template directory under fileadmin, and create a file mainTemplate.html with the following contents:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Site template</title>
</head>
<body>
<!-- ###DOCUMENT_BODY### begin -->
<div id="container">
<div id="leftContent">
<!-- ###LEFT_COLUMN### -->
Left Column Content
<!-- ###LEFT_COLUMN### -->
</div>
<div id="centerContent">
<!-- ###CENTER_COLUMN### -->
Center Column Content
<!-- ###CENTER_COLUMN### -->
</div>
<div id="rightContent">
<!-- ###RIGHT_COLUMN### -->
Right Column Content
<!-- ###RIGHT_COLUMN### -->
</div>
<div id="borderContent">
<!-- ###BORDER_COLUMN### -->
Border Column Content
<!-- ###BORDER_COLUMN### -->
</div>
</div>
<!-- ###DOCUMENT_BODY### end -->
</body>
</html>

Also, create a new CSS file in the same directory, called mainStyle.css with the following content:

#container {
width: 100%;
height: 100%;
}
#leftContent {
float: left;
width: 200px;
display: inline;
}
#centerContent {
float: left;
width: 500px;
display: inline;
}
#rightContent {
float: right;
width: 200px;
}
#borderContent {
float: right;
width: 200px;
}

Note

Case Sensitivity

Make sure you follow case sensitivity, as TypoScript code is case sensitive, and it doesn't see mainStyle.css as the same as mainstyle.css.

Come up with a convention for yourself. If you know all your names, follow camelCase, you will save yourself a lot of double checking and headaches when something doesn't work.

How to do it...

  1. 1. In the Template module, browse to the page you would like to be the root of the site. Create a new root template.

  2. 2. In the Includes tab, include the styles.content (default) static template.

    Note

    Any page can be the root of a new site, even if it's within an already defined page tree structure. By default, templates propagate through the tree, but a new template record can be set as root:

  3. 3. In the setup field, add the following code:

    page = PAGE page.typeNum = 0 page.10 = TEMPLATE page.10 { template = FILE template.file = fileadmin/templates/mainTemplate.html
    workOnSubpart = DOCUMENT_BODY subparts.LEFT_COLUMN < styles.content.getLeft subparts.RIGHT_COLUMN < styles.content.getRight subparts.BORDER_COLUMN < styles.content.getBorder subparts.CENTER_COLUMN < styles.content.get } page.includeCSS.mainStyle = fileadmin/templates/mainStyle.css
    

How it works...

There is a lot that happens in just a few lines. Let's refresh your TypoScript knowledge.

page=PAGE creates a new top-level page object, and page.typeNum=0 assigns a page type of 0 that is the default. So, when you go to the page with no type argument, this page object will be used.

Note

Other type numbers can be used to display content in a different form. For example, different type value can render a page for mobile device, for print, or even as XML for external applications, such as RSS feeds.

In the earlier code, page.10=TEMPLATE defines a content object at position 10 in the content object array. When the page is rendered, the content objects are each rendered in numerical order. Page.10 is defined as a TEMPLATE content object, so it will take an HTML template file, and process it. Lines template=FILE and template.file=fileadmin/templates/mainTemplate.html define the location of the template file that will be loaded. workOnSubpart=DOCUMENT_BODY tells the page object to use the DOCUMENT_BODY subpart section of the template.

At this time, the template file will be loaded and output as it is. However, the following lines replace the respective subparts with output from each column:

page.10 { subparts.LEFT_COLUMN < styles.content.getLeft subparts.RIGHT_COLUMN < styles.content.getRight subparts.BORDER_COLUMN < styles.content.getBorder subparts.CENTER_COLUMN < styles.content.get }

This is possible because we included the styles.content static template.

What will happen now is TYPO3 will get a list of all content elements in each column, and render them, that is, it will convert content into HTML. It will then place the resulting HTML code in place of the subparts.

The design in mainTemplate.html is very simple—just HTML. We want to apply some styling to that structure. Line page.includeCSS.mainStyle=fileadmin/templates/mainStyle.css includes our CSS file, which does just that.

There's more...

For more information about templates, you should read a detailed guide to templating in TYPO3: http://typo3.org/documentation/document-library/tutorials/doc_tut_templselect/current/ (Modern Template Building). We will briefly go through a few more features.

Markers vs. Subparts

In the mainTemplate.html file, we have used four subparts. This lets us preview the file, and see exactly where the content will go once it is rendered. Subparts are defined by a unique marker, enclosed in HTML comment tags, and surrounding some text, as in:

<div><!-- ###TEMPLATE_SUBPART### --> Code that will be replaced <!-- ###TEMPLATE_SUBPART### --></div>

Sometimes, you just want content to be inserted into a specific point, in such a case, you can use a marker. A marker is similar to a subpart, but exists by itself and doesn't reside in an HTML comment:

<div>###TEMPLATE_MARKER###</div>

Subparts are also used by extensions, where the subparts contain markers. This may not be clear at this point, but after working with a few templates you will grasp the difference.

Including JavaScript

To include JavaScript files, add the following lines to TypoScript:

page.includeJS.someCode = fileadmin/templates/someCode.js

See TypoScript Reference (TSref) for more options: http://typo3.org/documentation/document-library/references/doc_core_tsref/current/