Datamapper with Template library |
[eluser]mak.gnu[/eluser]
Hi, I'm using Template library and parser in my new project, along with Datamapper, Is there any way I can pass the datamapper object to the parser class.
[eluser]WanWizard[/eluser]
A Datamapper object is a variable like any other, so I don't see why not. Without more information I don't think anyone can give you a yes or no. Have you tried it? What was the result? Any error messages or other behaviour? Which template library? Which parser?
[eluser]mak.gnu[/eluser]
I'm using Codeigniter's built in parser, and Collin Wiliams Template library http://www.williamsconcepts.com/ci/libra...index.html I tried passing the object to via Code: $c = new Classified($id); In view I cannot see any value all the values are in brackets {} I think parser is not able to render the values
[eluser]WanWizard[/eluser]
It's been a while since I've used Colin's library, but I think the data parameter must be an array: Code: $this->template->parse_view('content', $this->page, array('classified' => $this->parsed)); And CI's parser library doesn't work with objects. {var} is replaced by the contents of the data by a simple str_replace(), so if the variable passed can't be cast as a string, this is not going to work. You could use the Datamapper array extension method to_array() to convert the object to an array, but I'm pretty sure the parser doesn't support that either. If you need a parser, go for a more established one, CI's parser is extremely basic, and not even documented.
[eluser]tarciozemel[/eluser]
@WanWizard Do you recommend some that accepts objects?
[eluser]WanWizard[/eluser]
Choosing a template parser is very personal, and difficult to recommend. It all depends on what you want from it. I've used Dwoo, Smarty, SimpleTags and Mustache, and they all do the job, though differently. I suggest you look at them, and pick one that works for you. For some of them, there are CI integration libraries available. This might be a selection criteria for you.
|
Welcome Guest, Not a member yet? Register Sign In |