主题继承的目的就是实现多主题共存下模板的继承,相应的配置在{theme name}/config.php的parent属性。 如果不填写属性值,则默认继承default主题。如果配置文件中没有parent属性则不继承任何主题,这个主题就必须包含template/layout-content.phtml,template/paginator.phtml,template/error-exception等模板,如果缺少了必须的模板,在主题安装的时候会看到缺少必要文件的提示信息。 例如,创建两个主题a、b。
{theme name}/config.php
parent
template/layout-content.phtml
template/paginator.phtml
template/error-exception
// b/config.php 'parent' => 'a'
// b/config.php 'parent' => '' // or you can set it as default 'parent' => 'default'
Pi系统的模块存放在usr/module/{module name}目录下,模块目录下的asset和template文件夹内存放的是和主题相关的文件,如果在主题包内没有相应文件则会使用该目录下的主题文件。 开发者可以在主题内创建相应文件夹以覆盖模块内主题文件。 在此以widget模块为例,在default theme内覆盖widget模块的slideshow。
usr/module/{module name}
default/module/widget
widget/ ├── asset/ │ └── css/ │ └── slideshow.css ├── template/ │ └── block/ ` └── carousel-bootstrap.phtml
asset
<?php $this->css($this->assetModule('asset/css/slideshow.css', 'widget')); ...
主题下一般都会有区块模板,有时候为了适应不同区域下区块的不同样式,会需要做多个区块模板。 例如,在主题包{theme name}/template路径下创建如下两个区块模板。
{theme name}/template
//block.phtml <div class="block"> <div class="block-header"></div> </div>
//block-noheader.phtml <div class="block-noheader"></div>
具体如何制作区块模板可以参考区块模板制作教程。 制作好区块模板后可以在主题下的{theme name}/template/layout-front.phtml根据需求,引入不同的区块模板。
{theme name}/template/layout-front.phtml
There was an error while loading. Please reload this page.