Back to Home

Create a theme for Drupal. Part 3

drupal · theme · design · theme creation

Create a theme for Drupal. Part 3

    image
    Part 1 , Part 2

    Patterns


    We will add templates in sites / all / themes / mytheme / templates . Create page.tpl.php templates for pages, node.tpl.php for content, block.tpl.php for blocks, comment-wrapper.tpl.php for a block with comments, comment.tpl.php for one comments, header.tpl.php for the header, footer.tpl.php for the footer, region.tpl.php for the regions. Also, by analogy with preprocesses, we can create files like node-story.tpl.php to display material like story or block-user.tpl.phpfor the user block. This allows you to separate separately different types of site content.

    I will not give HTML templates. Layout to your taste. I’ll only talk about the variables available for each template.

    page.tpl.php


    The basic template for the page.
    Available variables:
    • $ head_title - page title
    • $ head - all information in head
    • $ styles - styles
    • $ scripts - scripts
    • $ classes - classes for body
    • $ header - the header that we put in a separate template
    • $ REGION_NAME - variables with region names
    • $ messages - system messages
    • $ tabs - tabs
    • $ content - content
    • $ feed_icons - RSS icons
    • $ footer - the basement that we put in a separate template
    • $ base_path - the base path of the site
    • $ is_front - the main page or not
    • $ logged_in - whether the user is logged in
    • $ is_admin - admin or not
    • $ language - an object containing data about the current language
    • $ node - node
    • $ front_page - link to the main
    • $ logo - logo
    • $ site_name - site name
    • $ site_slogan - site slogan
    • $ mission - site mission
    • $ search_box - search block
    • $ closure - the variable is inserted before the closing tag / body, some modules write scripts to it. Thanks to juliv habrauser


    node.tpl.php


    Content output template.
    Available variables:
    • $ node - node object
    • $ classes - classes for the node
    • $ user_picture - user avatar
    • $ picture - node picture, redefined by modules
    • $ page - node page or list of teasers
    • $ unpublished - published or not
    • $ display_submitted - by whom and when published
    • $ terms - categories
    • $ content - content
    • $ links - links
    • $ title - title
    • $ date - creation date
    • $ name - author name
    • $ node_url - node link
    • $ comment_count - number of comments
    • $ type - material type
    • $ uid - author id
    • $ zebra - class for zebra
    • $ teaser - teaser or whole node
    • $ sticky - sticky or not
    • $ status - node status
    • $ comment - are comments included
    • $ is_front - on the main or not
    • $ logged_in - logged in or not
    • $ is_admin - admin or not


    region.tpl.php


    Region output template.
    Available variables:
    • $ classes - classes for the region
    • $ content - content
    • $ region - name of the region
    • $ is_front - on the main or not
    • $ logged_in - logged in or not
    • $ is_admin - admin or not


    block.tpl.php


    Block output template.
    Available variables:
    • $ block - block object
    • $ classes - block classes
    • $ title - title
    • $ content - content
    • $ edit_links - block edit links
    • $ zebra - zebra
    • $ block_id - block id
    • $ is_front - on the main or not
    • $ logged_in - logged in or not
    • $ is_admin - admin or not


    comment-wrapper.tpl.php


    Comment output block template.
    Available variables:
    • $ classes - classes
    • $ node - node
    • $ content - content
    • $ display_mode - a way to display comments
    • $ display_order - display order of comments
    • $ comment_controls_state - is there a comment management form


    comment.tpl.php


    Single Comment Display Template.
    Available variables:
    • $ classes - classes
    • $ picture - author avatar
    • $ title - title
    • $ new - new or not
    • $ unpublished - published or not
    • $ author - author
    • $ created - creation date
    • $ content - content
    • $ links - links


    header.tpl.php


    Website header template. We defined all the variables for this template ourselves in preprocess-header.inc
    Available variables:
    • $ front_page - home page or not
    • $ logo - site logo
    • $ search_box - search block
    • $ header_line - region named header_line


    footer.tpl.php


    Basement site template. All variables for this template we defined ourselves in preprocess-footer.inc
    Available variables:
    • $ footer_line - region named footer_line
    • $ page_bottom - a region named page_bottom


    What is the result


    As a result, we have a very flexible topic. We can add templates for different regions, materials, blocks just by creating a new file. We can add variables to new templates just by creating a new file and adding a couple of lines to it. We have selected all regions as separate templates, as well as the header and basement, which allows us not to duplicate their code in templates for different pages. You just have to make up and add styles and scripts to your taste (do not forget to write them in the info-file).

    Where does it come from


    Most of the information and ideas come from ZEN and SKY topics .

    Good luck in creating themes!

    Read Next