fuel / parser

Fuel PHP Framework - v1.x template parser package adapters
http://fuelphp.com
64 stars 45 forks source link

Request: A way to render a view without it being parsed #31

Closed phil-lavin closed 12 years ago

phil-lavin commented 13 years ago

JS libraries, such as handlebars, require the raw/unparsed template including in a <script></script> tag in order to use AJAX. The basic design pattern would be that a view.mustache would be created and data would be applied to it and it would be rendered parsed. You would then render it unparsed, wrapped in a script tag, and handlebars would handle the ajax request for JSON and the client side parsing of this.

jschreuder commented 13 years ago

Can't you just put that into a normal .php view?

phil-lavin commented 13 years ago

For now I have done that in the form of an include - so filters.php includes filters.mustache and that is passed to the main view in an unparsed form. It seems more elegant to be able to get the unparsed template from the parser package's View class.

phil-lavin commented 13 years ago

E.g.

Controller ...

<?php
// Get filters view of first subcategory
$this->template->content->filters = \View::forge('filters.mustache', static::get_response_data(reset($subcats)->id));

// Pass unparsed filter template to view
// @TODO - unhack this - see views/filters.php
$this->template->content->filters_markup = \View::forge('filters');

filters.php...

<?php
include('filters.mustache');
jschreuder commented 12 years ago

As we made extensions meaningfull for parsing they should remain meaningfull, anything else creates unnecessary ambiguity.

phil-lavin commented 12 years ago

What is your suggested solution to this problem?

jschreuder commented 12 years ago

I don't consider this a problem. The View class and the Parser package extended View class isn't meant to serve up unmodified templates, if you want that you need to just use File::read() or write a wrapper class yourself for serving these up.