2017-03-15 15 views
0

自分のプラグインを使用してテンプレートfrontend/home/index.tplを拡張しようとしています。フォルダのリソース\ビュー\フロントエンド\ホーム\Shopware 5.2.20。プラグインを使用してテンプレートを拡張できません

でここ
<?php 
namespace TdevExtend; 
use Shopware\Components\Plugin; 
class TdevExtend extends Plugin 
{ 
    public static function getSubscribedEvents(){ 
    return [ 
     'Enlight_Controller_Dispatcher_ControllerPath_Frontend_MyPlugin' => 
      'onDetailPostDispatch' 
    ]; 
    } 
    public function onDetailPostDispatch(\Enlight_Event_EventArgs $args) 
    { 
     $this->container->get('template')->addTemplateDir(
     $this->getPath() . '/Resources/views/' 
    ); 
    return __DIR__ . '/Controllers/Frontend/MyPlugin.php'; 
    } 
} 
?> 

があるdirrectoryコントローラでの私のコントローラ MyPlugin.php \フロントエンド

public function preDispatch() 
    { 
    /** @var \Shopware\Components\Plugin $plugin */ 
    $plugin = $this->get('kernel')->getPlugins()['TdevProductTab']; 

    $this->get('template')->addTemplateDir($plugin->getPath() . '/Resources/views/'); 
} 

テンプレート:ここ

私のルート・ファイル

{extends file="parent:frontend/home/index.tpl"} 
{block name='frontend_index_content'} 
    <div class="">Hello world!</div> 
    {$smarty.block.parent} 
{/block} 

私はofficial documentationを読んだ調査したプラグインの例plugins examples バックエンドにプラグインcrearキャッシュをインストール/再インストールした後、var/cacheにmanualyフォルダを削除した後。しかし、何も私を助けませんでした。

+1

は、URL https://developers.shopware.com/developers-guide/shopware-5-plugin-update-guide/#template-extensionsからあなたが欲しいものを得るでしょう –

+0

リンクは古いプラグインを示してい私は彼が新しいプラグインシステムを使用していると理解しています。 – Sadik

+0

はい、私は新しいシステムを使用しています。 – Andrii

答えて

1

Enlight_Controller_Dispatcher_ControllerPath_Frontend_MyPluginの代わりに、getSubscribedEventsのイベントEnlight_Controller_Action_PostDispatchSecure_Frontend_Indexを使用します。

イベントEnlight_Controller_Dispatcher_ControllerPath_Frontend_MyPluginを使用しています。コントローラをお探しの場合MyPlugin Shopwareがこのイベントを作成します。したがって、このイベントを使用する場合は、独自のコントローラを作成する必要があります。しかし、私はあなたが望むものは、上記のイベントだと思います。実際にはコントローラを作成する必要はありません。

<?php 
namespace TdevExtend; 
use Shopware\Components\Plugin; 
class TdevExtend extends Plugin 
{ 
    public static function getSubscribedEvents(){ 
    return [ 
     'Enlight_Controller_Action_PostDispatchSecure_Frontend_Index' => 
      'onPostDispatch' 
    ]; 
    } 
    public function onPostDispatch(\Enlight_Event_EventArgs $args) 
    { 
     $this->container->get('Template')->addTemplateDir(
     $this->getPath() . '/Resources/views/' 
    ); 
    } 
} 
?> 
+0

こんにちは@Sadik。それはあまりにも機能しません。ここに、[zip](https://drive.google.com/file/d/0B-uO_5Pl1EFBRGpWcnQ1QjRJaFU/view?usp=sharing)ウィジェットのプラグインのリンクがあります。確認していただけますか? xdebugブレークポイントは 'onPostDispatch'で動作するので、テンプレートに関するいくつかの問題があるかもしれません – Andrii

+0

あなたのzipファイルのプラグインはうまくいきます。ちょうどそれを/ custom/pluginsフォルダに入れてください。変更後にプラグインを再インストールする必要があることに注意してください。 – Sadik

+0

どのOSを使用していますか?私はWindowsを使用していますが、まだ私のために働いていません – Andrii

関連する問題