다음 프로젝트에서 Kohana와 함께 Mustache 템플릿을 사용할 계획입니다. 그래서 내가하려는 것은 Kohana가보기를 렌더링 할 때마다 매끄럽게 Mustache를 사용하도록 만드는 것입니다. 예를 들어, 내 views
폴더에이 파일이 것 : Kohana와 함께 템플릿 시스템을 원활하게 사용하고 있습니까?
myview.mustache
$view = View::factory('myview');
echo $view->render();
을 나는 일반보기로 할 것이다 것처럼. Kohana는 이런 종류의 것을 허용합니까? 그렇지 않다면 모듈을 사용하여 직접 구현할 수있는 방법이 있습니까? (그렇다면, 가장 좋은 방법 무엇을 할 것인가?)
PS : 나는 Kostache 살펴했지만, 나를 위해 직접 콧수염 PHP를 사용하는 것과 동일한 사용자 정의 구문을 사용합니다. 나는 Kohana의 구문을 사용하여 그것을 찾고 있습니다.
편집 : 정보
, 이것은 내가 @의 erisco의 답변에 따라, 그 일을 결국 방법이다.
전체 모듈
은 GitHub의에서 사용할 수 있습니다 : Kohana-Mustache에서 APPPATH/클래스/view.php : 예, 당신이 할 수있는
<?php defined('SYSPATH') or die('No direct script access.');
class View extends Kohana_View {
public function set_filename($file) {
$mustacheFile = Kohana::find_file('views', $file, 'mustache');
// If there's no mustache file by that name, do the default:
if ($mustacheFile === false) return Kohana_View::set_filename($file);
$this->_file = $mustacheFile;
return $this;
}
protected static function capture($kohana_view_filename, array $kohana_view_data) {
$extension = pathinfo($kohana_view_filename, PATHINFO_EXTENSION);
// If it's not a mustache file, do the default:
if ($extension != 'mustache') return Kohana_View::capture($kohana_view_filename, $kohana_view_data);
$m = new Mustache;
$fileContent = file_get_contents($kohana_view_filename);
return $m->render($fileContent, Arr::merge(View::$_global_data, $kohana_view_data));
}
}
Kostache가 자체 공장을 사용하는 유일한 차이점은 무엇입니까? 나에게 문제가되지 않는다. –