печать содержимого файла smarty - PullRequest
0 голосов
/ 22 июля 2011

Я включаю шаблон, как это:

<div id="comments" >
      {include file='comm/comm_all.tpl'}
</div>

, и я хотел бы передать содержимое comm_all.tpl в HTML.Что-то в этом роде:

<div id="comments" >
      {include file='comm/comm_all.tpl'}
</div>
<div id="code_preview" >
      the code previw is:
      {include_function file='comm/comm_all.tpl'}
</div>

я включил функцию включения, и он

должен взять содержимое файла и напечатать «как есть», например:

<div id="comments" >
      1. bla bla the show
      2. it`s an array as you guess.
</div>
<div id="code_preview" >
      the code previw is:
      {foreach $array as $i => $v}
           $i. {$v.content}
      {/foreach}

</div>

1 Ответ

0 голосов
/ 22 июля 2011

Если я вас правильно понимаю, то, что вы хотите сделать, не в Smarty, но это можно сделать с помощью функции плагина в PHP.

<?php

    function include_function($params, $smarty){

        $filename = "{$smarty->template_dir}/{$params['file']}";

        if(file_exists($filename)){
            readfile($filename);
        }

    }

?>

<div id="comments" >
      {include file='comm/comm_all.tpl'}
</div>
<div id="code_preview" >
      the code previw is:
      {include_function file='comm/comm_all.tpl'}
</div>
...