CodeIgniter Forums
Printing out object properties or array values in CI's Template class - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Printing out object properties or array values in CI's Template class (/showthread.php?tid=25397)



Printing out object properties or array values in CI's Template class - El Forum - 12-10-2009

[eluser]BrianDHall[/eluser]
OK, so I want to do the following in a view using the template class:

Code:
<p>Listing Address: {listing->address}</p>

I notice this, of course, does not work. Accessing an array element using the template class also doesn't work.

Is anyone aware of a good upgrade to CI's template class I can drop in (not Smarty, just something slick and relatively thin) that allows even such extremely minor sorts of features?

I know I can pre-load the variables I feed to the view and I suppose this is what I'll do, but it just seemed like it would be so nice to just do something like the above Sad


Printing out object properties or array values in CI's Template class - El Forum - 12-10-2009

[eluser]theprodigy[/eluser]
I'm not really knowledgable in using CI's template class, but what happens if you assign an array to a template variable, and then output the variable? Does the template class allow straight PHP? Is there an equivalent of print_r in the templating class (to see what it gets set as)?


Printing out object properties or array values in CI's Template class - El Forum - 12-10-2009

[eluser]Ben Edmunds[/eluser]
Phil Sturgeon integrated Dwoo nicely with CI. It's similar to smarty but lighter.


Printing out object properties or array values in CI's Template class - El Forum - 12-10-2009

[eluser]Jamie Rumbelow[/eluser]
[quote author="Ben Edmunds" date="1260506653"]Phil Sturgeon integrated Dwoo nicely with CI. It's similar to smarty but lighter.[/quote]

...and sexier.


Printing out object properties or array values in CI's Template class - El Forum - 12-16-2009

[eluser]BrianDHall[/eluser]
Dudes, Phil Sturgeon's implementation of Dwoo is sooo sexy!

It works just like I wanted!

Code:
controller:

$array['messages'][] = array('text' => 'hello');
$array['messages'][] = array('text' => ' ');
$array['messages'][] = array('text' => 'world');
$array['messages'][] = array('text' => '!');

view:

I would just like to say, {loop $messages}&lt;?php echo $text; ?&gt;{/loop}

And it actually works - you can mix PHP code right inside a set of Dwoo {loop} tags, no muss, no fuss.

I never thought I'd say it, but a templating engine is actually awesome, specifically as implemented by Phil in CI = Dwoo is the shiznit, and its impact on baseline performance seems altogether tolerable Smile