Warp架构中文说明——Theme layout 模板布局

模板布局

两个核心PHP文件确定主题的布局和样式。本节将学习如何显示小部件位置和他们的显示方式

THEME.PHP

每个主题的核心文件都是 theme.php. 这不同于标准的Joomla模板使用 index.php 文件作为主要文件

下面是 theme.php.的主题结构, 它需要导入的文件 theme.config.php呈现小部件位置,检索配置变量和渲染系统的输出。

<?php

// get theme configuration
include($this['path']->path('layouts:theme.config.php'));

?><!DOCTYPE HTML>
<html lang="<?php echo $this['config']->get('language');?>" dir="<?php echo $this['config']->get('direction');?>"  data-config='<?php echo $this['config']->get('body_config','{}');?>'>

  <head>
  <?php echo $this['template']->render('head');?>
  </head>

  <body>

    // render a widget position
    <?php echo $this['widgets']->render('widget-position');?>

    // retrieve a config variable
    <?php echo $this['config']->get('variable');?>

    // render the system output
    <?php echo $this['template']->render('content');?>

  </body>

</html>

配置对象

在 config.xml 获取值,存储在 config 对象.读取有效的值, 使用 get 方法.

// output the value of the branding variable<?php echo $this['config']->get('theme_branding');?>

// output the to-top scroller based on the theme setting<?php if($this['config']->get('totop_scroller')):?><a class="tm-totop-scroller" data-uk="smooth-scroll" href="#"></a><?php endif;>

Widget object

The widgets of the page are stored in the widgets object. To render all widgets in a position, use the render method. You can check, whether any widgets are published in a position, by using the count method.

<// render all widgets in Top A position
<?php echo $this['widgets']->render('top-a'));?>

// apply the parallel layout to all widgets in Top A position
<?php if($this['widgets']->count('top-a')):?><?php echo $this['widgets']->render('top-a', array('layout'=>'parallel'));?><?php endif;?>

THEME.CONFIG.PHP

While the theme.php basically only defines the theme's markup, the logic is outsourced to the theme.config.php. It is responsible for calculations, like the 3 column layout as well as the body classes and social buttons.

在中国六艺专注Joomla建站与策划设计,为您的品牌发展创造动力!