プロが教える店舗&オフィスのセキュリティ対策術

よろしくお願いします。

まずphpファイルから
$smarty->display('111/body.tpl');(*111はディレクトリ名)
を呼び出して、さらにbody.tplと同ディレクトリにあるcontents.tplを読み込もうとしています。

はじめのbody.tplは読み込むことができブラウザで表示されるのですが、contents.tplは読み込めず、
Warning: Smarty error: unable to read resource: "contents.tpl" in <絶対パス>/Smarty/Smarty.class.php on line 1095
のエラーが出てしまいます。

ちなみに/111/というディレクトリは、$template_dir以下、$template_dir/111/です。

{include file="contents.tpl"}
{include file="file:contents.tpl"}
{include file="絶対パス/contents.tpl"}
{include file="file:絶対パス/contents.tpl"}
など試しましたが、ダメでした。

知恵をお貸しください。よろしくお願いします。

A 回答 (2件)

まずcontents.tplのみを呼び出して実行出来ますか?



templatesにフォルダを分けているなら、
下記のようになります。

/templates/ 
 ├ body.tpl
 ├/111/
   └contents.tpl
 ├/222/
   └contents.tpl

body.tplを呼び込んで、その中で、
{include file="111/contents.tpl"}
{include file="222/contents.tpl"}

で読み込めると思うのですが。


$this->template_dir = "/home/public_html/templates";
$this->compile_dir = "/home/public_html/templates_c";
$this->config_dir = "/home/public_html/conf";

Windowsの場合は、
$this->template_dir = "C:/home/public_html/templates";
    • good
    • 0
この回答へのお礼

>f_motionさん
何度もありがとうございます。
{include file="111/contents.tpl"}
↑で解決しました。

念のため、状況をご報告します。

ファイルの配置は下記の通りです。

├index.php
└/templates/ 
   ├/111/
     ├ body.tpl
     └ contents.tpl
   ├/222/
     ├ body.tpl
     └ contents.tpl

また設定は、仰る通りです。
$this->template_dir = "/home/public_html/templates";
$this->compile_dir = "/home/public_html/templates_c";
$this->config_dir = "/home/public_html/conf";

この状態でindex.phpから、
$smarty->display('111/body.tpl');
は読み込めます。
ただ、body.tplから
{include file="111/contents.tpl"}・・・(1)
は読み込めますが、
{include file="contents.tpl"}・・・(2)
ではダメでした。

てっきり呼び出し元のbody.tplと、読み込むcontents.tplが同ディレクトリなので、(2)の記述でいいと考えてしまっていました。

勉強になりました。本当にありがとうございました。

お礼日時:2006/09/21 17:18

テンプレートの位置を多分指定していると思いますが、



それを、下記のように絶対パスで指定すれば大丈夫だと思います。

$this->template_dir = "/home/public_html/111/templates";
$this->compile_dir = "/home/public_html/111/templates_c";
$this->config_dir = "/home/public_html/111/conf";

呼び出すときは、どこからでも下記ような感じで呼び出せます。
{include file="contents.tpl"}

この回答への補足

重ねて質問になってしまうのですが、

{include file="contents.tpl"}
に絶対パスを使用してみたのは、111ディレクトリが下記ページの例7-8に該当すると考えたためです。
http://sunset.freespace.jp/smarty/SmartyManual_2 …

これでダメということは、他の原因(ディレクトリ指定やhtaccess)がありそうということでしょうか。

よろしくお願いいたします。

補足日時:2006/09/21 14:58
    • good
    • 0
この回答へのお礼

回答どうもありがとうございます。

言葉足らずでしたので、追加いたします。
111というディレクトリを作ったのは、他にも222のようなディレクトリを作って、そちらにもテンプレートを置きたいと考えているからです(数字で場合分け)。
さらに上位のtemplatesも111もテンプレートの入る状態にはできないのでしょうか?
/templates/ 
 ├ *.tpl
 ├/111/
   └*.tpl

回答の通りにしましたところ、上位のtemplatesディレクトリのテンプレートが読み込めませんでした。

お礼日時:2006/09/21 14:35

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!