CodeIgniter Forums

Full Version: how integrate smarty with codeigniter
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]Ehsan-ul-haq[/eluser]
hi

i would like to integrate smarty with codeigniter ,


any one please help me to to do this....

El Forum

El Forum

[eluser]Dam1an[/eluser]
Bargainph,you forgot the most important link of all, lmgtfy Wink

El Forum

[eluser]Thorpe Obazee[/eluser]
[quote author="Dam1an" date="1244637864"]Bargainph,you forgot the most important link of all, lmgtfy Wink[/quote]

Yeah, forgot about that Tongue

El Forum

[eluser]Phil Sturgeon[/eluser]
Here's a quick guide on how to "Access CodeIgniter helpers from Smarty templates". Use this once you have Smarty up and running.

El Forum

[eluser]the5threvolution[/eluser]
[quote author="Phil Sturgeon" date="1244641695"]Here's a quick guide on how to "Access CodeIgniter helpers from Smarty templates. Use this once you have Smarty up and running.[/quote]

His code is extremely useful.

Couple of corrections though.

1. File name is modifier.helper.php not helper.modifier.php
2. Directory you should put this file is plugins under smarty library, not directly under CI plugins folder.
3. You need to add unset($params[2]); before return.

So in smarty, (from the example from the link..)
{$item.url|helper:'url':'anchor':$item.title:'class="more params"'}
$item.url is the first parameter of the helper function
$item.title is the second parameter of the helper function
and anything after that pretty much follows.
In this case, it's like anchor($item.url, $item.title, 'class="more params"');
Those variables can be assigned from php, or hard coded in tpl file, up to you.

Thank you Phil Sturgeon!

El Forum

[eluser]Phil Sturgeon[/eluser]
I have never tested this code but a few people told me it worked fine so just went ahead and posted it up. Lazy I know :-$

I agree with all your points but not sure why I would need to unset $params[2]. That would be the 3rd argument which would work out as the first actual parameter. In this example, unset $params[2] would wipe off $item.title!

El Forum

[eluser]the5threvolution[/eluser]
[quote author="Phil Sturgeon" date="1247757761"]I have never tested this code but a few people told me it worked fine so just went ahead and posted it up. Lazy I know :-$

I agree with all your points but not sure why I would need to unset $params[2]. That would be the 3rd argument which would work out as the first actual parameter. In this example, unset $params[2] would wipe off $item.title![/quote]

Hello,

When I ran it and echoed all the parameters passed; print_array($params) before $params[0] = $string;,

from the example {$item.url|helper:‘url’:‘anchor’:$item.title:‘class=“more params”’},

$params[0] = $item.url
$params[1] = 'url'
$params[2] = 'anchor'
$params[3] = $item.title
$params[4] = 'class="more params"'

So, without unset $params[2], all the parameters were shifted and the example gave the output as: "Check out this amazing item
Code:
<em><a href="http://localhost/contact/index.php/test">anchor</a></em>
...
(I cannot add code properly, but it's like ..."index.php/test" this is the title> ...)

Here's the output and test code:
Code:
print_r($params);
echo "<br><br><br>";
$params[0] = $string;
unset($params[1]);
print_r($params);
echo "<br><br><br>";
unset($params[2]);
print_r($params);
echo "<br><br><br>";

Output was... ($item.url was "test" and $item.title was "this is the title")
Array ( [0] => test [1] => url [2] => anchor [3] => this is the title [4] => class="more params" )
Array ( [0] => test [2] => anchor [3] => this is the title [4] => class="more params" )
Array ( [0] => test [3] => this is the title [4] => class="more params" )

I wonder if different smarty version makes a difference? I think I have the latest smarty though..

Thank you~