0
템플릿 클래스에서 작업하고 있는데 tpl 파일에서 편집 가능한 LOOP을 만들지 않아도됩니다. (나는 Smarty 또는 다른 프레임 워크를 사용하지 않는다).템플릿을 편집 할 수있는 루프 만들기 (PHP)
<ul>
{TABLE_ROWS}
</ul>
가 {TABLE_ROWS가} PHP 루프에서 구문 분석 : :이처럼 내 .tpl 파일이
while($row = mysql_fetch_array($query))
{
$content = $this->tools->cutString(strip_tags($row['content']), 100);
$time = date("m/Y", $row['time']);
$table_rows .= "<li>
<strong>" . $time . "</strong> » " . $content . "
<div class='riadokZmien'><a href='" . ADMIN_URL . "shortnews/edit/" . $row['id'] . "' class='edit'><strong>Upraviť</strong></a><a href='" . ADMIN_URL . "shortnews/delete/" . $row['id'] . "' onclick=\"return confirm('Naozaj vymazať? Tento krok už nepôjde vrátiť späť.');\" class='del'><strong>Odstrániť</strong></a>
</div></li>";
}
$replace = Array(
'TABLE_ROWS' => $table_rows,
);
$this->loadTemplate('shortnews');
// .......
if(isSet($replace) && $replace)
$this->parseTags($replace);
을하지만, 페이지 템플릿이 완전히 변경되는 경우는 효과가 없습니다. 그런 다음 모듈에서 코드를 편집해야합니다.
나는 다음과 같이 그것을 해결하는 것을 시도하고있다 :
<ul>
{TABLE_ROWS_START}
<li><strong>{row.TIME}</strong> {row.CONTENT}
<div class='riadokZmien'><a href="{ADMIN_URL}shortnews/edit/{row.ID}' class='edit'><strong>Upraviť</strong></a><a href="{ADMIN_URL}shortnews/delete/{row.ID}" onclick=\"return confirm('Naozaj vymazať? Tento krok už nepôjde vrátiť späť.');\" class='del'><strong>Odstrániť</strong></a>
</div></li>
{TABLE_ROWS_END}
</ul>
이나 뭐 이런 및 루프와 같은 PHP에서이 구문 분석,하지만 내가 어떤 좋은 생각이없는
이 loadTemplate 방법입니다 :
public function loadTemplate($tpl_name)
{
$path = ($this->admin === false ? TEMPLATES_PATH : ADMIN_TPL_PATH);
if(file_exists($path . $this->template_folder . DS . 'tpl' . DS . $tpl_name . '.tpl'))
{
$this->content = file_get_contents($path . $this->template_folder . DS . 'tpl' . DS . $tpl_name . '.tpl');
}
else
{
die ('Cannot load main template: ' . $path . $this->template_folder . DS . 'tpl' . DS . $tpl_name . '.tpl');
}
}
그리고 parseTags 방법있다 :
public function parseTags($replace = Array())
{
$replaced = Array();
foreach ($replace as $key => $value)
{
$replaced['{' . $key . '}'] = $value;
}
$this->content = str_replace(array_keys($replaced), array_values($replaced), $this->content);
}
은3210
도움 주셔서 감사합니다.
예를 들어 템플릿의 문을 처리 할 수있는 방법이 있습니까? 만약 title2가 있다면 보여 주겠습니까? 그렇지 않으면하지 않습니까? – Ralf
아니요. 이제 [Twig] (http://twig.sensiolabs.org/) 템플릿 엔진과 함께 프레임 워크를 사용하고 있습니다. 나는 너에게 그것을 추천 할 수있다. 이 엔진은 거의 모든 기능을 갖추고 있으며 사용자가 원하지 않는 기능이 있습니다. 사용자 정의 필터를 추가하기 만하면됩니다. :) –