2

タイトルがまだあなたを怖がらせていない場合は、読み進めてください. ExpressionEngine Web サイトで作業しており、メンバー テンプレート ファイルを編集しています。メンバーの相互作用に関連するすべてのテンプレートは、クラス内の関数として 1 つのファイルに格納されます。

これらの各関数は単純なヒア ドキュメントですが、それらの多くは、私が使用したくないパスと用語を含むコードを出力します。たとえば、この Web サイトでは、ログインしているユーザーを「メンバー」ではなく「クライアント」と呼びます。

とにかく、これらの値を抽象化して、現在および将来のプロジェクトで簡単に変更できるようにする方法を探しています。現在、変数を各関数内で定義することにより、ヒア ドキュメント内に変数を出力できます。クラスが定義される前に、ファイルの先頭でこれらの値を定義したいのですが、ヒアドキュメントでこれらの値を認識できません。

要約されたサンプル ファイルを次に示します。

<?php
/* I wish to define variables once in this area */
$globaluserterm = "client";

class profile_theme {

//----------------------------------------
//  Member Page Outer
//----------------------------------------
function member_page()
{
$userterm = "client";
return <<<EOF
<div id="{$userterm}-content">
    <h1>{$userterm} Account</h1> (Note: This DOES work)
    <h1>{$globaluserterm} Account</h1> (Note: This doesn't work)
    {include:member_manager}
</div>
EOF;
}
/* END */

//-------------------------------------
//  Full Proile with menu
//-------------------------------------
function full_profile()
{
$userterm = "client";
return <<< EOF
<div id="{$userterm}-full-profile">
    {include:content}
</div>
EOF;
}
/* END */


}
// END CLASS
?>
4

2 に答える 2

3

ファイルごとにクラスが1つしかない場合は、クラスレベルで値を定義するだけで十分でしょうか。例えば

class profile_theme {
    private $globaluserterm = "client";
    //....
}

および関数内:

return <<<EOF
<div id="{$userterm}-content">
    <h1>{$userterm} Account</h1> (Note: This DOES work)
    <h1>{$this->globaluserterm} Account</h1> (Note: This doesn't work)
    {include:member_manager}
</div>
EOF;
于 2010-06-18T16:04:04.097 に答える
1

あなたが何をしようとしているのか完全には理解できませんが、あなたが探しているのはSmartyのようなテンプレート エンジンだと思います。(より無駄のない代替案については、この質問を参照してください。)

Smarty では、テンプレート ファイルを準備します。

<div id="{$userterm}-content">
    <h1>{$userterm} Account</h1> (Note: This DOES work)
    <h1>{$globaluserterm} Account</h1> (Note: This doesn't work)
    {include:member_manager} /* Don't know how to do this in smarty */
</div>

変数値を事前入力します。

$Smarty = new Smarty();
// ... set up caching etc. if needed  ...

$Smarty->assign("userterm", $value1);
$Smarty->assign("globaluserterm", $value2);
..... 

これがあなたが探しているものではない場合、あなたが何をしたいのかをより詳細に説明できますか?

于 2010-06-18T15:58:06.647 に答える