mastering typo script

Download Mastering typo script

Post on 15-Jan-2015



Investor Relations

10 download

Embed Size (px)




."A block of code will be set as follows:temp.mainTemplate = TEMPLATEtemp.mainTemplate {template = FILEtemplate.file = fileadmin/_temp_/hello.htmWhen we wish to draw your attention to a particular part of a code block, the relevant lines or items will be made bold:$template = $this->cObj->getSubpart($template,"###BODY_CONTENT###");$template_reference = $this->cObj->getSubpart($template, "###REFERENCE###");$result = $GLOBALS["TYPO3_DB"]->exec_SELECTquery("*","user_references_main",New terms and important words are introduced in a bold-type font. Words that you see on the screen, in menus or dialog boxes for example, appear in our text like this: "The Table name field determines the name of the new table."Warnings or important notes appear in a box like this. 23. Preface[ ]Tips and tricks appear like this.Reader FeedbackFeedback from our readers is always welcome. Let us know what you think about this book, what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.To send us general feedback, simply drop an email to, making sure to mention the book title in the subject of your message.If there is a book that you need and would like to see us publish, please send usa note in the SUGGEST A TITLE form on or there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on SupportNow that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.Downloading the Example Code for the BookVisit, and select this book from the list of titles to download any example code or extra resources for this book. The files available for download will then be displayed.The downloadable files contain instructions on how to use them.ErrataAlthough we have taken every care to ensure the accuracy of our contents, mistakes do happen. If you find a mistake in one of our booksmaybe a mistake in text or codewe would be grateful if you would report this to us. By doing this you can save other readers from frustration, and help to improve subsequent versions of this book. If you find any errata, report them by visiting support, selecting your book, clicking on the Submit Errata link, and entering the details of your errata. Once your errata have been verified, your submission will be 24. Preface[ ]accepted and the errata added to the list of existing errata. The existing errata can be viewed by selecting your title from can contact us at if you are having a problem with some aspect of the book, and we will do our best to address it. 25. Introduction to TypoScriptTYPO3 is one of the most popular Content Management Systems in use today. This is hardly surprising, given that it can handle large web projects comfortably. However, if you want to have control not only over the content but also the design and functionality of your online presence, you require a good knowledge of TypoScript. This book introduces you to TypoScript and shows you how to create templates, generate menus and frames, and prepare your website for search engines.PrerequisitesThis book is targeted at experienced TYPO3 users and is meant to help youprimarily during your day-to-day work. However, before you start with TypoScript, we must clarify the selection of packages and extensions that need to be installed to use this book. It does not matter in principle which TYPO3 package you have installedTypoScript can be learned with any package. The following instructions are based on an installed dummy package.Dummy PackageYou of course want to use TypoScript for your own projects. As already mentioned, it does not matter in principle which TYPO3 package you have installed. However, for starting out with TypoScript the dummy package is recommendedyou get an empty database and can experiment with TypoScript as much as you want. The installation of the dummy package is not shown here. You can download the dummy package from up an Example Page StructureYou have bought this book to learn to use TypoScript in your own projects. Here TypoScript is explained using small independent examples, so that the book serves 26. Introduction to TypoScript[ ]as a reference without you having to work through a large example or case study. However, some topics, such as the template auto-parser can only be explained with the help of a detailed example page structure. So in order to avoid having to define a new example each time in such cases, the following steps define a specific one. You can use the book quite well even if you don't use this example structure; however it makes things easier. The time spent on creating the example pages is less than5 minutes.First right-click TYPO3 and point to New. In the right frame New record click on Page (inside):Give this page a title (e.g. Index); disable the Hide page checkbox in the upper area of the window and save the page.Call the Index page and click on Functions in the left menu. Make sure that the Create multiple pages wizard is selected in the drop-down list as pages can be created quite easily using this wizard.All you have to do is to enter the desired page titles. 27. Chapter 1[ ]The pages are created via the Create pages button. You can inspect the results immediately in the page tree.You can now assign sub-pages to the newly created pages. To do this, point to About Us, select the Create multiple pages wizard again, and create a few sub-pages.Repeat these steps for additional pages. The result should look like this in the page tree:That's it. You can always build on this sample installation and keep coming back to it. 28. Introduction to TypoScript[ 10 ]Declarative Programming with TypoScriptThe name TypoScript is confusing. TypoScript is not a classical script, let alone a programming language in the usual sense. It cannot even be classified as a descriptive language similar to HTML. What then is TypoScript? To answer this question you must take a look at the basic principle of all Content Management Systemscontent and layout must be separated from each other and can be manipulated through templates and stylesheets. Tags that are dynamically replaced by the CMS's content are preferred. The type of tag varies mostly between and {Tag}, but the principle is always the same.But TYPO3 doesn't stop herebecause of the ability to create the complete output template with TypoScript, the developer has full control over the layout. The influence of this template on the final design in comparison to normal HTML templates is disproportionately higher.Then what is TypoScript? The statement that it is not a programming language is not entirely true, since TypoScript, strictly speaking, can be regarded as a declarative programming language. TypoScript is a tool with which you specify what the output of the website and/or TYPO3 will look like. In contrast to a true programming language, you simply use TypoScript to describe the look of the result; the actual path to the solution is not programmed.The Power of TypoScriptUnlike many other CMSs, TypoScript goes much beyond allowing you to integrate dynamic contents. Thanks to TypoScript, JavaScript-based menus, Flash, Graphics, etc. can be integrated with ease. You have maximum control over the design ofthe website and can control all options that would otherwise be addressed by HTMLsimple text output, formatting, and much more. TypoScript also allows you to generate graphics at run time and the display of content can be changed according to the time of day or the user group.What does this multiplicity of functions mean to you? To begin with it saves you time learning TypoScript. Even though TypoScript is only a declarative programming language, you first have to get familiar with the syntax. Luckily, TypoScript is not as complex as PHP or Java. Although the ambitious TYPO3 developer may find this to be a limitation in some areas, this reduces potential errors. If you have developed complex menus via JavaScript, you know about the problems that crop up until the menu finally works reliably. For example, take a look at a really simple drop-down menu as used on numerous websites.Please choose!Page 1Page 2Page 3Page 4This example illustrates some of the aspects and problems of JavaScript menus. If you want to create this type of menu, you have to understand JavaScript. Furthermore, you must have experience as to what browser the syntax works with and how to compensate for functions that create errors in others. Don't forget that this is a really simple example. When we approach dynamic websites, the effort and the likelihood of errors increase. If, for example, you want to provide semi-transparent navigation using graphics and layers, you have to have a thorough knowledge of HTML, DHTML, and JavaScript. The size of such scripts quickly bloats up to several hundred lines. It therefore takes some time before everything is running properly. The debugging adds to the difficulties. How does TypoScript circumvent these? What are its strengths? Take a look at the following menu:page.10.marks.MENU.1 = GMENUpage.10.marks.MENU.1.expAll = 1page.10.marks.MENU.1.NO{backColor = #000000XY = 100, 2010 = TEXT10.text.field = title10.fontColor = #ffffff10.offset = 4,1410.fontFile = fileadmin/verdana.ttf10.fontSize = 11wrap = |
}page.10.marks.MENU.2 = GMENUpage.10.marks.MENU.2.NO 30. Introduction to TypoScript[ 12 ]{backColor = #c0c0c0XY = 100, 2010 = TEXT10.text.field = title10.fontColor = #ffffff10.offset = 4,1410.fontFile = fileadmin/verdana.ttf10.fontSize = 10wrap = |
}This is how menus are created in TypoScript. The example shown