What fetch() does
Use fetch() to render a template without sending output—it returns an HTML string. That fits Ajax responses or when you need the markup as a value.
Example
php
class index {
function docs() {
$data = array(
'status' => 1,
);
$list = m('essay')->where($data)->select();
assign('docs_list', $list);
$html = fetch('docs'); // home/view/index/docs.html
ajax(0, $html);
}
}fetch() vs v()
fetch()— render and return HTML.v()— render and output, then end the request (typical page response).
Argument forms
Assume the current request is /home/index/docs.
fetch('')— default template for the action:/home/view/index/docs.htmlfetch('docsInfo')—docsInfo.htmlunder the current controller view folder.fetch('index:docs')— explicit controller/view mapping (segment before:).fetch('admin@index:docs')— another module (@before the module name).