0

私はTypo3が初めてです。/typo3conf/ext/myExtension に myExtension という拡張機能を作成しました

フォルダ構成は以下の通り

-Classes
 --ViewHelpers
   --myExtensionViewHelper.php
-Resources
 --Resources
  --Private
   --Templates
    --myExtension
     --index.html

myExtensionViewHelper.php には次のコードがあります

<?php

/**
 * This class is a demo view helper for the Fluid templating engine.
 *
 * @package TYPO3
 * @subpackage Fluid
 * @version
 */
class Tx_myExtension_ViewHelpers_myExtensionViewHelper extends Tx_Fluid_Core_ViewHelper_AbstractViewHelper {

    /**
     * Renders some classic dummy content: Lorem Ipsum...
     *
     * @param int $length The number of characters of the dummy content
     * @validate $length IntegerValidator
     * @return string dummy content, cropped after the given number of characters
     */
    public function render($length) {
        $dummyContent = 'Lorem ipsum dolor sit amet.';
        return substr($dummyContent, 0, $length);
    }
}

?>

index.html ファイルに含まれる

{namespace myExtension=Tx_myExtension_ViewHelpers} 

<f:layout name="Default" />
<f:section name="content">

<h1>
  <myExtension:myExtension length="5" />
</h1>

</f:section>

Typo3 バックエンドで、「Mango」というページを作成し、このプラグインをそこに含めました。

Webページ「Mango」のテンプレート、レイアウト、およびtemplate.htmlがあります。

ファイル Index.html の出力をこのページに取り込むにはどうすればよいでしょうか?

私はこれを正しくやっていますか?ここに挙げたもの以外は何もしていません。

私はTypo3にまったく慣れていないので、これはすべて理解するのが少し難しいです. 些細で明白なことがあったとしても、言及してください。

ありがとう :)

4

1 に答える 1

3

テンプレート システムをロードしてテンプレートを表示するコントローラが必要です。定義した ViewHelper は、結果を取得するために必須ではありません。これらは、テンプレートで使用できる単なるカスタム テンプレート クラスです。

コントローラーの例:

ファイル: Classes/Controller/TestController.php

class Tx_MyExtension_Controller_TestController extends Tx_Extbase_MVC_Controller_ActionController {
    /**
     * action sampleAction
     *
     * @return void
     */
    public function sampleAction() {
        //Add variables to template
        $this->view->assign("sample_var", "sample value");
    }

}

ここで、Controller と Action に基づくディレクトリにあるテンプレート ファイルが必要です。したがって、このサンプルmy_extension/Resources/Private/Templates/Test/では、​​ action のように呼び出されるテンプレート ファイル (「Test」はコントローラー名) が必要Sample.htmlです。

my_extension/Resources/Private/Layouts/Default.html拡張機能をラップするには、コンテンツを含むレイアウト ファイルも必要です。

<div class="tx-my-extension">
    <f:render section="main" />
</div>

このファイルは<f:layout name="Default" />テンプレートで呼び出さ<f:render section="main" />れ、コンテンツが表示される場所になります。

次のステップは、拡張機能でアクションを許可することです。ext_localconf.phpルート ディレクトリに移動し、追加します。

Tx_Extbase_Utility_Extension::configurePlugin(
    $_EXTKEY,
    'Myextension',
    array(
        'Test' => 'sample', // 'ControllerName' => 'ActionName, OtherAction'
    ),
    // non-cacheable actions
    array(
        'Test' => 'sample', // 'ControllerName' => 'ActionName, OtherAction'
    )
);

最後のステップはmy_extension/Resources/Private/Templates/Test/Sample.html、コンテンツを含むテンプレート ファイルを作成することです。

<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">

<f:layout name="Default" />

<f:section name="main">
    Your sample var: {sample_var}
</f:section>

プラグインをページに追加すると、結果が表示されるはずです。

于 2013-05-06T15:26:42.600 に答える