<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    posts - 431,  comments - 344,  trackbacks - 0

    As of Drupal 4.7, themes can implement any number of regions for rendering blocks and other content into. If you take a look at the 'blocks' administration page in Drupal, you will see that regions are essentially containers to which you can add those blocks. You can also add other non-block content to a region using PHP. An example of a region is your sidebar.

    These regions can be assigned to either the whole page or any other themed elements, including in nodes or comments.

    The PHPTemplate engine defines five default regions: left, right, content, header, and footer. To implement these regions, themes need only include $sidebar_left, $sidebar_right, $content, $header, and $footer_message variables in their page.tpl.php files, e.g., <?php print $header; ?>.

    How to define custom regions

    If you want to have your own set of regions for a theme, you do this by defining a _regions() hook. In this case, your custom regions will override those defined by default in PHPTemplate.

    If the theme doesn't have a template.php file in its directory, create one; otherwise use the existing template.php file. In either case, add a mytheme_regions() function to define your regions. Each region needs to have a name (a string with no spaces) and a description (the text that will show up in, for example, the block configuration pages). The following would define all the standard PHPTemplate regions except the left sidebar and, in addition, two new regions for a theme called "mytheme".

    <?php
    function mytheme_regions() {
      return array(
       
    'right' => t('right sidebar'),
       
    'content' => t('content'),
       
    'header' => t('header'),
       
    'footer' => t('footer'),
       
    'floater' => t('floater'),
       
    'inline1' => t('inline 1')
      );
    }
    ?>

     

    Note: Regarding the name of the function:

    • use the name of your theme instead of mytheme_regions(), eg: bluemarine_regions()
    • Don't use a hyphen in the name of a region; an underscore is OK.
    • Also, your theme name is your base theme name not the name of your style.css directory (if you are using one). For example, box_cleanslate overrides the style.css file of the box_grey theme; therefore you should name your function box_grey_regions.

    How to write the theme's region variables to the page.

    If you're assigning your region to page.tpl.php, you don't need to worry about creating a variable for your region and assigning content to it; PHPTemplate handles this automatically. All you need to do is write the variables to the page, by editing your theme's page.tpl.php file. For each new region you've defined, include in page.tpl.php a print call. For the 'floater' region defined above, this would look like:

    <?php  print $floater;?>.

    Of course, you'll probably want to use HTML, CSS, and possibly PHP (e.g., if tests) to get your new regions looking how you want them.

    Inline regions: how to assign regions to nodes, comments, etc.

    By default, all defined regions are passed to page.tpl.php. But with an extra step you can also choose to make specific regions available to any other template file: node.tpl.php, comment.tpl.php, etc. Here's how.

    In the same template.php file as you defined the regions in, define a function _phptemplate_variables() (or use an existing one if there's one already defined). What you'll do here is assign region content to a specific theme call. When _phptemplate_variables() is called, it receives the theme argument as the $hook variable, for instance 'node'. So we can assign new regions to the node template like this:

    <?php
    function _phptemplate_variables($hook, $variables) {
     
    // Load the node region only if we're not in a teaser view.
     
    if ($hook == 'node' && !$vars['teaser']) {
       
    // Load region content assigned via blocks.
       
    foreach (array('inline1') as $region) {
         
    $variables[$region] = theme('blocks', $region);
        }
      }
      return
    $variables;
    }
    ?>

     

    Note that we're testing to make sure we aren't in a 'teaser' view, so that the region will be loaded only in a full node view.

    Now, in your node template, you can include the region variable in your output. Here's the standard phptemplate node.tpl.php with an 'inline1' region added:

      <div class="node<?php if ($sticky) { print " sticky"; } ?><?php if (!$status) { print " node-unpublished"; } ?>">
        <?php if ($picture) {
          print
    $picture;
        }
    ?>

        <?php if ($page == 0) { ?><h2 class="title"><a href="<?php print $node_url?>"><?php print $title?></a></h2><?php }; ?>
        <span class="submitted"><?php print $submitted?></span>
        <span class="taxonomy"><?php print $terms?></span>
        <div class="content"><div class="floatleft"><?php print $inline1?></div><?php print $content?></div>
        <?php if ($links) { ?><div class="links">&raquo; <?php print $links?></div><?php }; ?>
      </div>

     

    Likely you'll want to add style declarations to the region, which you do as usual via the theme's style.css file. Here, for example, we could make the inline region float left:

    div.floatleft {
      float: left;
    }

     

    Because a node's variables are passed to other node templates, you can also do your customized display in node-type templates.

    And this same basic approach can be applied to any other themed area. This example assigns specific regions to nodes and comments:

    <?php
    function _phptemplate_variables($hook, $variables) {
     
    // Load region content assigned via blocks.
      // Load the node region only if we're not in a teaser view.
     
    if ($hook == 'node' && !$variables['teaser']) {
        foreach (array(
    'node1', 'node2') as $region) {
         
    $variables[$region] = theme('blocks', $region);
        }
      }
      else if (
    $hook == 'commment') {
        foreach (array(
    'comment1', 'comment2') as $region) {
         
    $variables[$region] = theme('blocks', $region);
        }
      }
      return
    $variables;
    }
    ?>

     

    Regions without blocks

    If you want to assign content to regions but not have it output via blocks, do so with the drupal_set_content() function. This allows you to bypass the regular block system. Try something like this:

    Set content to regions
    In your module code, set content to the regions. You can use region names that aren't listed in your themename_regions() array. That way, the regions won't be available for blocks, and so won't end up with block content in them. Say your regions are called 'region1' and 'region2'. In your module code, do this:

    <?php
    $output
    = 'whatever';
    drupal_set_content('region1', $output);
    ?>

     

    In a template.php file, set a variable and assign the region content to it.

    <?php
    function _phptemplate_variables($hook, $variables) {
     
    // Load region content assigned via drupal_set_content().
     
    if ($hook == 'page') {
        foreach (array(
    'region1', 'region2') as $region) {
         
    $variables[$region] = drupal_get_content($region);
        }
      }
      return
    $variables;
    }
    ?>

     

    Output your content
    In your page.tpl.php file, output the regions where you want them:

    <?php
    print $region1;
    ?>

     

    posted on 2007-11-06 11:49 周銳 閱讀(160) 評論(0)  編輯  收藏 所屬分類: PHP
    主站蜘蛛池模板: 精品国产日韩亚洲一区| 欧洲美熟女乱又伦免费视频| 亚洲一级毛片视频| 日本不卡免费新一区二区三区| 亚洲尤码不卡AV麻豆| 亚洲男人天堂2022| 四虎影院免费在线播放| 亚洲AV无码之国产精品| 日韩在线不卡免费视频一区| 免费国产成人高清在线观看麻豆| 国产亚洲色婷婷久久99精品| 青柠影视在线观看免费高清| 国产黄色片在线免费观看| 亚洲最新视频在线观看| 亚洲性线免费观看视频成熟| 在线精品亚洲一区二区三区| 日韩欧美亚洲国产精品字幕久久久| 曰皮全部过程视频免费国产30分钟| 精品国产亚洲第一区二区三区| 中文字幕久久亚洲一区| 免费精品一区二区三区第35| 亚洲一区精品伊人久久伊人| 免费国产成人α片| 亚洲国产熟亚洲女视频| 国产真人无遮挡作爱免费视频| 特级毛片爽www免费版| 亚洲s色大片在线观看| 黄床大片免费30分钟国产精品 | 免费在线观看视频a| 国产福利电影一区二区三区,免费久久久久久久精 | 少妇高潮太爽了在线观看免费| 亚洲精品乱码久久久久久V| av在线亚洲欧洲日产一区二区| 日本在线免费观看| 亚洲人成电影网站色www| 亚洲精品色婷婷在线影院| 中国xxxxx高清免费看视频| 色偷偷亚洲男人天堂| 亚洲AV午夜成人片| 毛片免费全部播放一级| 9久久免费国产精品特黄|