LoginSignup
0
0

More than 5 years have passed since last update.

同じブロックで別テンプレートファイルを使えるようにする

Last updated at Posted at 2013-04-02

一部のモジュールはブロック編集画面でどのテンプレートファイルを使って表示するかを変更できるようになっています。

でも多数のモジュールではブロックのテンプレートファイルを変更することができません。

今回Bulletinの新着ニュースブロックを2箇所で使い、それぞれデザインを変えたかった(テンプレートを別にしたかった)ので、ブロック管理画面を改造しちゃいました。

スクリーンショット

改造したのはXOOPS Cube Legacy2.1系です。(ブロック周りに変更少なければXCL2.2、momoxoでも組み込めるとおもいます)

html/modules/legacy/admin/templates/block_edit.html フォーム内に下記追加

      <tr>
          <td class="head"><{$smarty.const._AD_LEGACY_LANG_TEMPLATE}></td>
          <td class="<{cycle values="odd,even"}>">
              <{xoops_input type=text name=template value=$actionForm->get('template') size=20 class=legacy_list_number}>
          </td>
      </tr>

html/modules/legacy/admin/forms/BlockEditForm.class.php

prepareメソッド内で下記追加

        $this->mFormProperties['template'] =& new XCube_StringProperty('template');

        $this->mFieldProperties['template'] =& new XCube_FieldProperty($this);
        $this->mFieldProperties['template']->setDependsByArray(array('maxlength'));
        $this->mFieldProperties['template']->addMessage('maxlength', _MD_LEGACY_ERROR_MAXLENGTH, _AD_LEGACY_LANG_TEMPLATE, '255');
        $this->mFieldProperties['template']->addVar('maxlength', '255');


loadメソッドに下記追加

        $this->set('template', $obj->get('template'));

updateメソッドに下記追加

        $obj->set('template', $this->get('template'));

これでブロック編集画面でテンプレートファイル名が指定できるようになってます。

あとはテーマ下テンプレート機能使ってテーマ下に配置したり、AltSysでカスタムテンプレート作製したりですかね。

2013/05/06追記

この方法だとブロックの新規インストールで問題が発生。要修正

2013/06/04追記

ブロックの新規インストールに対応するためには html/modules/legacy/admin/templates/blockinstall_edit.htmlも修正する

82行目あたり

      <td colspan="2" class="foot">
        <input class="formButton" type="submit" value="<{$smarty.const._INSTALL}>" />
        <input class="formButton" type="submit" value="<{$smarty.const._BACK}>" name="_form_control_cancel" />
      </td>

上記にtemplateについての記述を追加して下記の様にする

      <td colspan="2" class="foot">
          <{xoops_input type=hidden name=template value=$actionForm->get('template') }>
        <input class="formButton" type="submit" value="<{$smarty.const._INSTALL}>" />
        <input class="formButton" type="submit" value="<{$smarty.const._BACK}>" name="_form_control_cancel" />
      </td>

これでブロック新規インストールでも大丈夫です。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0