关于区块自由布局需要注意的问题[新手]

作者 wyf.scott 于 1293101595
接触xoops时间不长,如果理解有误,欢迎指正。

这两天在摆弄xoops的区块管理,在自由布局区块的时候碰到了一个问题。我把区块显示的代码放在system_homepage.html文件中代码下:

<div class="xo-blockszone x2-secondary" id="xo-page-topcblocks">
    <{foreach 
from=$xoBlocks.page_topcenter item=block}>
      <{if 
$block.id eq 14}>
        <
div class="xo-block <{$block.module}>">
            <{if 
$block.title}><div class="xo-blocktitle"><{$block.title}></div><{/if}>
            <
div class="xo-blockcontent"><{$block.content}></div>
        </
div>
      <{/if}>
    <{/foreach}>
</
div>

代码是没问题的,可以正常的把区块ID为14的区块显示在首页上,但是有个前提:ID为14的区块在"区块管理"里面的"是否可见"必需设为"是",否则该代码是不起任何作用的。但是如果将区块设为可见,我们再次调用的话,那么该区块就输出了两次了,不是我们想要的结果。所以还有个地方需要修改。那就是你使用的当前主题对应的theme.html文件,将该区块所在位置屏蔽掉。我的修改如下:

<{if $xoBlocks.page_topleft or $xoBlocks.page_topcenter or $xoBlocks.page_topright}>
    <
div class="xo-blockszone xo-<{$theme_top_order}>pageblocks" id="xo-page-topblocks">
        <{*
includeq file="$theme_name/centerblocks.html" topbottom=top lcr=$theme_top_order|substr:0:1*}>
        <{
includeq file="$theme_name/centerblocks.html" topbottom=top lcr=$theme_top_order|substr:1:1}>
        <{
includeq file="$theme_name/centerblocks.html" topbottom=top lcr=$theme_top_order|substr:2:1}>
    </
div>
<{/if}>

如此改动之后,就能得到预期的输出了。

个人觉得如果可以直接读取数据库,然后去判断区块ID,将符合条件区块输出就好了,这样就不用管后台的区块设置了,而且也不用屏蔽掉theme.html里的区块相关位置(因为屏蔽后,那个位置所有的区块都不能显示了),这样就更加灵活了。方法肯定是有的,只是我还没撑握,希望知道的朋友不吝赐教。

参考资料:《XOOPS Theme设计宝典》

谢谢

来自: http://xoops.org.cn/newbb/viewtopic.php?topic_id=33378&post_id=81444