.. You may want to use the usual include line. Uncomment and adjust the path. .. include:: ../Includes.txt ================================== Modern Template Building, Part 2+3 ================================== :Author: Kasper Skårhøj :Created: 2002-11-01T00:32:00 :Changed by: Donald Duck :Changed: 2003-04-01T01:33:21 :Author: Kasper Skårhøj :Email: kasper@typo3.com :Info 3: :Info 4: .. _Modern-Template-Building-Part-2-3: Modern Template Building, Part 2+3 ================================== **Extension key: doc\_tut\_templselect2** Copyright 2003, Kasper Skårhøj, This document is published under the Open Content License available from http://www.opencontent.org/opl.shtml The content of this document is related to TYPO3 \- a GNU/GPL CMS/Framework available from www.typo3.com .. _Table-of-Contents: Table of Contents ----------------- **Modern Template Building, Part 2+3 1** **Introduction 1** What does it do? 1 **Part 2: Creating a Template Selector 2** Introduction 2 Preparations 3 Investigating the source material 4 Creating an extension 12 Modifying item arrays (backend) 14 Reading the selected template (frontend) 20 A TypoScript session for Mr. Benoit 25 The content area template 28 Real content in the columns 30 Setting the default template with a constant 33 Configuration of the template paths 35 Conclusions 36 **Part 3: Extending the Built-In Access Scheme 38** Introduction 38 The theory of "enablefields" 38 Extending the t3lib\_pageSelect class 39 Changing the "fe\_group" field 42 Adding our custom "enablecolumn" type 43 Access control on user level? 44 Extending access control for pages 44 .. _Introduction: Introduction ------------ .. _What-does-it-do: What does it do? ^^^^^^^^^^^^^^^^ This is Part 2 and 3 of the tutorial "Modern Template Building" from the "doc\_tut\_templselect" extension. For developers on intermediate to expert level. For further introduction see the intro-section of Part 1. .. _Skill-levels: Skill levels """""""""""" Part 1 of this tutorial contained: **The Basics** - a newbee introduction to building websites with TYPO3, template records, TypoScript and Content Objects (cObjects). Any person who wants to develop with TYPO3 should be familiar with the concept described here. **Part 1: Integration of an HTML template** - this part aims specifically at intermediate HTML-webdesigners with a limited amount of technical knowledge. *Notice: The Basics and Part 1 are found in another document, in the extension "doc\_tut\_templselect"* This part (2+3) contains: **Part 2: Creating a Template Selector** - this part aims at intermediate web developer with good knowledge of PHP, SQL and programming concepts in general. **Part 3: Extending the Built-In Access Scheme** - for advanced TYPO3 /PHP-developers. .. _Part-2-Creating-a-Template-Selector: Part 2: Creating a Template Selector ------------------------------------ .. _Introduction: Introduction ^^^^^^^^^^^^ Most websites will do fine having only one main template and nothing more. Normally alternative designs are only about substitution of a single image or a stylesheet and most likely such changes are supposed to work within a certain level of the page tree. For instance a customer service section might have its own header image to set the environment of that section. Or another common feature is to have a totally different template for the frontpage, possibly some kind of entrance choice. These features can often be done without invoking a whole new template file (except from the unique front page of course) but simply by setting some conditional properties inside the template record. .. _The-challenge: The challenge """"""""""""" However we will now take the basic example from the previous section in this tutorial and expand it heavily so that instead of one template file we can select from any number of template files per page and per section. Further we want the content area to be more flexible having different sub-templates for columns, news sections etc. And all this should be made so flexible that new templates can be added by Mr. Raphael (the designer) simply by creating the file in the right location! At the same time the non-technical authors/editors should be able to select from these templates on a per-page basis in a visually intuitive way. .. _The-technical-outlines: The technical outlines """""""""""""""""""""" The illustration below outlines what we need in order to achieve our goal: |img-1| As you can see the main structure (light blue section) is the same as in the previous section. However the template file delivered to the "plugin.tx\_automaketemplate\_pi1" USER cObject must be selected based on which template file is selected for the current page/template. Further the insertion of page content elements must be done based on the currently selected content area template which will be combined with content from one or more columns by a TEMPLATE cObject (the light yellow section). In the backend we need to add selector boxes for the templates in the page records. The content of these selectors must be dynamically loaded by some logic that looks up template files from a designated location in the file system. Thus Mr. Raphael can add new templates by the act of just creating a new template file there! The selectors should be equipped with icons representing the template options visually, something like this: |img-2| .. _Skill-level: Skill level """"""""""" *Intermediate to advanced web developer. Requires skills with PHP. Developer experience with TYPO3 and extension development is highly recommended.* To complete this section of the tutorial you should be a developer minded type of person. It requires you to know PHP and furthermore I'll be less explicit than in the previous section. So you will have to enable your brain during this section and figure out what's between the lines once in a while. .. _Preparations: Preparations ^^^^^^^^^^^^ To complete this section of the tutorial you should perform these steps no matter if you went through the previous section or not: - **Copy files:** Remove old content in the fileadmin/template/ folder, then copy the content from the folder "part2/" of this tutorial extension to fileadmin/template/. You should now have a directory structure with content equal to this: |img-3| - **Create page tree:** *Unless* you did the previous section of the tutorial you need to create a page structure in the database. The easiest way to do this is to import the trd-file "part1\_result\_pagetree.t3d" by following these steps: - Copy the file "part1/part1\_result\_pagetree.t3d" from the tutorial extension to "fileadmin/" - In the backend, create a new page on root level, call it "Import folder " and select the type "sysFolder". - Click the page/sysFolder icon of the new page, select "More options...", select "Import from .t3d". - Select the t3d file in the selectorbox, press preview. You should now see something like this: |img-4| - Press "Import": Now, the page tree starting with "Root page" should be created inside the "Import folder". - Cut the "Root page" and paste it into the root of the tree so you get "Root page" as the first page in the tree from the top. - The "Import folder" still contains three template records which are related to the main template record on the "Root page" - let them stay in the "Import folder" and rename the folder to "Template Storage". - **Install Kickstart Wizard:** Make sure the Kickstart Wizard extension ("extrep\_wizard") is installed: |img-5| .. _Investigating-the-source-material: Investigating the source material ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Before we move on with the creation of the extension it's very important to analyse the material we have at hand here. What we will do now is a kind of reverse-enginering where we take a set of templates and figure out what subparts we will need. Normally you would work the other way around: You would define what you need, then let the designer loose. For instance you might say "I want a template with two columns, one for NORMAL column content and one for RIGHT column content." - and the designer would make that by creating a template which has two table cells with id attributes that will place the subparts for NORMAL and RIGHT column content at the right position. .. _The-main-templates: The main templates """""""""""""""""" The main templates Mr. Raphael made are stored in the folder "fileadmin/template/main/". There are currently two main templates there: **template\_1.html:** |img-6| This is the same template as in Part 1 of this tutorial. **template\_2.html:** |img-7| This is an alternative main template. It includes a "path-menu" (Root page > First page > ....), a horizontal menu of current-page sub items and a content area which spreads over the full width of the page. For each of these templates Raphael also made a little icon. He gave the icons the same name as the template file, but with the "gif" extension instead: **template\_1.gif:** |img-8| **template\_2.gif:** |img-9| As you can see these icons are designed to reflect the overall structure of the main templates. Now, lets just look inside of the template\_2.html file for a second: |img-10| Notice the title of the document - we will use this for the main template selector box! This template uses an additional stylesheet! The template has a "path-menu" in a table cell with the id "path" The main menu is contained in a *table row* with id "menu\_2" (#5) and each element is wrapped in a element. "menu\_2" is the id of the table row (see #4) The class "oddcell" is used for every second menu item - this will produce alternating background colors The class "menu2-level1-act" is used to define the style for active elements in the menu. The id "content" is used - as with template\_1.html - for the table cell defining the content area of the main template. .. _Content-area-templates: Content area templates """""""""""""""""""""" In the folder "fileadmin/templates/sub/" we find four templates for different layouts of the content area of either of the main templates. Thus we have two main templates times four content area templates - a total of 8 possible combinations! .. ### BEGIN~OF~TABLE ### .. _img-11: |img-11| ~~~~~~~~ .. container:: table-row Layout |img-11| Info **ct\_1.html** Single Large Content Area (default) **Icon:** |img-12| .. _img-13: |img-13| ~~~~~~~~ .. container:: table-row Layout |img-13| Info **ct\_2.html** Wide Main Column, narrow right column. **Icon:** |img-14| .. _img-15: |img-15| ~~~~~~~~ .. container:: table-row Layout |img-15| Info **ct\_3.html** Three even Columns (left + normal + right) **Icon:** |img-16| .. _img-17: |img-17| ~~~~~~~~ .. container:: table-row Layout |img-17| Info **ct\_4.html** Single Large Content Column with News Section in Upper Right Corner. **Icon:** |img-18| .. ###### END~OF~TABLE ###### As you can see only the content area changes in Mr. Raphaels templates. In fact the menu and header image are just a background image inserted temporarily so that the content area designs could be evaluated in the right context! Lets take a look at the source code of the template file ct\_1.html: |img-19| Each template file has a page title which is carefully describing the template properties - this will in fact be the title used for the selector box inside of TYPO3s backend. This