• ベストアンサー

現在PHPとsmartyを勉強しているのですが、config_load

現在PHPとsmartyを勉強しているのですが、config_loadを利用して#HOGE#をテンプレート内で利用しています。 ここで、{include file="hoge.tpl" title=#TITLE#}のような使い方をしているのですが、title="hogehoge{#TITLE#}"のような使い方はできません。 (TITLEのデリミタ{}を外しても、#TITLE#とそのまま表示されてしまいます。 属性値に{#HOGE#}と文字列を合わせて使うにはどうすればよいか御教示ください。

質問者が選んだベストアンサー

  • ベストアンサー
  • JaneDue
  • ベストアンサー率75% (263/350)
回答No.1

バックスラッシュで展開できます。 {include file="hoge.tpl" title="hogehoge`$smarty.config.TITLE`"} ※ $smarty.config.TITLE は#TITLE# の別書式。#TITLE#ではダメなようですね。

ideal16
質問者

お礼

あれから私も調べて、同じ解答に行き着きました。 まさにおっしゃる通りです! ありがとうございます!

全文を見る
すると、全ての回答が全文表示されます。

関連するQ&A

  • smartyについて

    smartyにでサイトを作る際のテンプレート構造について質問です。 現在はindex.phpで $smarty->display('hoge.tpl'); としhoge.tplは {include file="./common/header.tpl"} <div id="contents"> {include file="./common/left_side.tpl"} <div id="center"> ここに表示する内容 </div> {include file="./common/right_side.tpl"} </div> {include file="./common/footer.tpl"} のようにしています。 表示する内容はそれぞれ違うものの全てではありませんがincludeする tplは他のページもほぼ同様ですのでもっと効率的にできるのでは?と 思うのですがどんな方法があるでしょうか?

    • 締切済み
    • PHP
  • Smarty includeでテンプレートを読み込めない

    よろしくお願いします。 まず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"} など試しましたが、ダメでした。 知恵をお貸しください。よろしくお願いします。

    • ベストアンサー
    • PHP
  • Smartyのエラーが2つずつ出ます

    PHP5+Smartyでサイトを作っています。 「$smarty->display("hoge.tpl");」としてテンプレートファイルを呼び出します。 そのテンプレートファイル「hoge.tpl」が存在しない時に、以下のエラー文が必ず2つ表示されます。 Warning: Smarty error: unable to read resource: "hoge.tpl" in /root/.../smarty/Smarty.class.php on line 1092 一度しか呼び出していないのにエラーが2つ表示されるので、コードの記述ミスかと考えたのですがわかりませんでした。 テンプレートファイルがある場合は、テンプレートが二度呼び出されることはありません。 エラー文にある1092行目からコードを追って見たのですがわかりませんでした。 どうすればエラー表示を1つにできるのでしょうか? 宜しくお願いします。

    • 締切済み
    • PHP
  • PHP(smarty)についての質問(文字化け)

    あるサイトでsmartyを勉強中ですが、そのサンプルファイルを実行したところ、 文字化けが発生して困っています。 ・form.php←お問い合わせ用テンプレートファイルの指定 ・form.tpl←お問い合わせ情報を入力させるテンプレートファイル ・template.tpl←テンプレートファイルを表示させるテンプレートファイル form.phpから、お客様情報を入力させるためのテンプレートファイル(form.tpl)を指定し、 template.tplにそれを表示させるのが処理概要です。 実行すると、タイトルの"問い合わせフォーム"は表示されますが、 それ以下のform.tplの日本語部分が文字化けします。 template.tplで{include file=$content_tpl params=$params}の処理で form.tplを取り込んでいますが、その時文字コードがおかしくなっている気がします。 form.tplに対して文字コード(UTF-8)が有効になっていないと思われます。 実験的に、{include file=$content_tpl params=$params}を削除して、 そこにform.tplの記載をすべて記述すると文字化けは起こりませんでした。 文字コードの指定をform.tplに対しても有効にするにはどのように修正すればよろしいでしょうか。 以下にソースファイルを記載します。 ★form.php <?php // 共通の設定を読み込む require_once( 'common.php' ); // Smartyオブジェクト取得 $smarty =& getSmartyObj(); // ひな形のSmartyテンプレートでincludeするテンプレートを指定 $smarty->assign( 'content_tpl', 'form.tpl' ); // パラメータを渡す $smarty->assign( 'params', array( 'types' => array( 'request' => '意見、要望', 'question' => '質問、問い合わせ', 'other' => 'その他' ) ) ); // ページを表示する $smarty->display( 'template.tpl' ); ?> ★form.tpl <p>お問い合わせやご意見・ご要望を以下のフォームにご記入の上ご送信ください。</p> <form method="post" action="post.php"> <dl> <dt>お名前</dt> <dd> <input type="text" name="name" value="{$params.name|escape:'html':'UTF-8'}" /> {if $params.errors.name} <p class="error-message">名前を入力してください。</p> {/if} </dd> <dt>メールアドレス</dt> <dd> <input type="text" name="address" value="{$params.address|escape:'html':'UTF-8'}" /> {if $params.errors.address} <p class="error-message">アドレスが不正です。</p> {/if} </dd> <dt>お問い合わせ種類</dt> <dd> {html_options name="type" options=$params.types selected=$params.type} {if $params.errors.type} <p class="error-message">お問い合わせ種類が不正です。</p> {/if} </dd> <dt>お問い合わせ件名</dt> <dd> <input type="text" name="title" value="{$params.title|escape:'html':'UTF-8'}" /> {if $params.errors.title} <p class="error-message">件名を入力してください。</p> {/if} </dd> <dt>お問い合わせ内容</dt> <dd> <textarea name="content" cols="60" rows="5"> {$params.content|escape:'html':'UTF-8'} </textarea> {if $params.errors.content} <p class="error-message">お問い合わせ内容を入力してください。</p> {/if} </dd> </dl> <input type="submit" value="送信する" /> </form> ★template.tpl <?xml version="1.0" encoding="utf-8" ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>問い合わせフォーム</title> <style type="text/css"> {literal} .error-message{ margin:5px; font-size:80%; color:red; } {/literal} </style> </head> <body> <h1>問い合わせフォーム</h1> {include file=$content_tpl params=$params} </body> </html> ★common.php <?php define( 'SMARTY_DIR', 'C:/xampp\php/smarty/libs/' ); require_once( SMARTY_DIR .'Smarty.class.php' ); // Smartyオブジェクト取得 function & getSmartyObj() { static $smarty = null; if( is_null( $smarty ) ){ $smarty = new Smarty(); $smarty->template_dir = 'C:/xampp/php/smarty/templates/'; $smarty->compile_dir = 'C:/xampp/php/smarty/templates_c/'; $smarty->config_dir = 'C:/xampp/php/smarty/configs/'; $smarty->cache_dir = 'C:/xampp/php/smarty/cache/'; } return $smarty; } ?>

    • ベストアンサー
    • PHP
  • Smartyエラーについて

    いつもお世話になっております。 Smartyのエラーが解決できなくて困っています。 お手数ですが、後教授願えないでしょうか。 使用環境:Ubuntu Eclipse [エラー] Fatal error: Uncaught exception 'SmartyException' with message 'Unable to load template file 'list.tpl'' in /home/mobapendev/public_html/Smarty/sysplugins/smarty_internal_template.php:163 Stack trace: #0 /home/mobapendev/public_html/Smarty/sysplugins/smarty_internal_template.php(550): Smarty_Internal_Template->isExisting(true) #1 /home/mobapendev/public_html/Smarty/Smarty.class.php(338): Smarty_Internal_Template->getRenderedTemplate() #2 /home/mobapendev/public_html/Smarty/Smarty.class.php(382): Smarty->fetch('list.tpl', NULL, NULL, NULL, true) #3 /home/mobapendev/public_html/mobapen/list.php(20): Smarty->display('list.tpl') #4 {main} thrown in /home/mobapendev/public_html/Smarty/sysplugins/smarty_internal_template.php on line 163 ディレクトリ構成 Smarty/Smarty.class.php Project/list.php Project/php/common.php project/smarty/templates/list.tpl project/smarty/templates_c project/smarty/cache project/smarty/configs となっており、 common.phpにて、 $dir = getcwd(); $smarty->template_dir=$dir .'/smarty/templates'; $smarty->compile_dir=$dir .'/smarty/templates_c'; $smarty->config_dir=$dir .'/smarty/configs'; $smarty->cache_dir =$dir .'/smarty/cache'; list.phpにて require_onceで取り込みまいしたが、 $smarty->display("list.tpl"); ディレクトリは間違っていないとは思っているのですが、 どこでload出来てていなか分からず、攻め上げいている状況です。 以上、宜しくお願い致します。

    • ベストアンサー
    • PHP
  • ロリポップでSmartyのtpl読み込みエラー

    下記のコードを実行すると、  Smarty error: unable to read resource: "template1.tpl"  というエラーが出てしまいます。 $smarty->template_dirで指定したディレクトリ名の中に  "template1.tpl"というファイルは配置してあります。  原因などわかればおしえていただけないでしょうか。 index.php <?php require_once("Smarty.class.php"); $smarty = new Smarty; $smarty->template_dir = './templates/'; $smarty->compile_dir = './templates_c/'; $smarty->config_dir = './configs/'; $smarty->cache_dir = './cache/'; $smarty->display("template1.tpl"); ?> 【サーバ】  ロリポップです。 【その他】 index.phpをホームディレクトリ配下におくとエラーは消えます。 【ディレクトリ構成】 modules/index.php と templates/template1.tpl をがあり、 index.php から template1.tpl を読み込もうとしています。  ・modules →index.php ・templates →template1.tpl

    • ベストアンサー
    • PHP
  • Smartyについて教えてください。

    Smartyについて教えてください。 参考書によってテンプレートの存在するディレクトリを指定している場合(1)と していない場合(2)がありますが、 どちらが正しいのでしょうか? (1) ********************************************* require_once('smarty/libs/Smarty.class.php'); $smarty = new Smarty(); $smarty->template_dir = "template02/"; $smarty->compile_dir = "compile/"; $smarty->display("content.tpl"); ********************************************* (2) ********************************************* require_once('smarty/libs/Smarty.class.php'); $smarty = new Smarty(); $smarty->display("content.tpl"); *********************************************

    • ベストアンサー
    • PHP
  • Smartyについて

    Smartyについて Smartyをインストールしました。 OS:ubuntu インストール先:/usr/local/lib/Smarty-2.6.26 php.ini[include_path]の設定:/usr/local/lib/Smarty-2.6.26/libs/を追加 /var/www/以下にtestフォルダ作成 /var/www/test/index.html | /test/index.php chmod 644 | /tempalates chmod 775 templates | / index.tpl chmod 644 /templates_c chmod 775 templates_c /configs chmod 775 configs /cache chmod 775 cache index.phpの内容 <?php require_once(”Smarty.class.php"); $o_smarty=new Smarty(); $o_smarty->template_dir="./templates/"; $o_smarty->compile_dir="./template_c/"; $o_smarty->assign("name","world"); $o_smarty->display("hello.tpl"); ?> index.tplの内容 <html> <head> <title>Hello,world</title> </head> <body> Hello,{$name}! </body> </html> http://web.domain/test/index.php を入力するとエラーは出ませんが、何も表示されません。 これだけで、原因を特定出来ないのかもしれませんが、何処が悪いのでしょうか? 御教示お願いいたします。

  • smarty上で、動的にファイルをインクルードするには

    現在、smartyを使用して、tplファイルを作成しています。 テンプレートファイル内で、条件によって呼び込むファイルを 変更したいのですが、下記のように includeの中で、変数を使う事は出来ないのでしょうか? {include file=$file}

    • ベストアンサー
    • PHP
  • 共通テンプレートを呼ぶ

    src/common/header.tplを src/hoge/hoge.tplから {include file="../common/header.tpl"} として呼びだしたい。 エラーメッセージが Warning: Smarty error: (secure mode) accessing "../common/header.tpl" is not allowed in C:\php\libs\Smarty.class.php on line 1088 です。 #### 設定 php.ini include_path = ".;C:\php\libs;C:\php\PEAR" safe_mode = Off Smarty.class.php $smarty->template_dir="."; {include file}を絶対パスで記述しても同じエラーです。 おそらくこのsecure modeの設定が正しく設定されていないのでしょうが その設定方法がいまいちよくわかりません。 簡単なことなのかもしれませんが、ご存知の方がいらっしゃいましたら ご教授願えないでしょうか。 よろしくお願いいたします。 環境 Windows XP php-5.0.5 Smarty-2.6.10

    • 締切済み
    • PHP