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

[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.
#2

[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?
#3

[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);

        //$c->include_related('user/group',array('name'),FALSE);
        $c->where('id',$id)->include_related('truck',array('brandName','modelName'),FALSE)->get();
        $this->parsed = $c;
        $this->page = 'show';
        $this->display();




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

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

[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.
#5

[eluser]tarciozemel[/eluser]
@WanWizard

Do you recommend some that accepts objects?
#6

[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.
#7

[eluser]tarciozemel[/eluser]
@WanWizard

I'll check them out. Thank you!




Theme © iAndrew 2016 - Forum software by © MyBB