Welcome Guest, Not a member yet? Register   Sign In
Datamapper with Template library

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.

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?

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

$c = new Classified($id);

        $this->parsed = $c;
        $this->page = 'show';

function display() {
        // Write to $title
        $this->template->write('title', $this->view['title']);
        $this->template->parse_view('content', $this->page,  $this->parsed);
        // Render the template

In view I cannot see any value all the values are in brackets {} I think parser is not able to render the values

It's been a while since I've used Colin's library, but I think the data parameter must be an array:
$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.


Do you recommend some that accepts objects?

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.


I'll check them out. Thank you!

Theme © iAndrew 2016 - Forum software by © MyBB