raintpl3 icon indicating copy to clipboard operation
raintpl3 copied to clipboard

Include with local variables feature

Open kargnas opened this issue 11 years ago • 0 comments

{include "file.tpl" $var="1"}

This will works in smarty. As $var is local variable. It can be migrated to raintpl like this:

{$var="1"}
{include="file"}

But this will occur a problem like this: Smarty $smarty->assign('user', User::myInstance('myidentifier'));

{foreach $users as $key => $userItem}
    user{$key}: {include "userIdentnfier.tpl" user=$userItem}
{/loop}
myId: {$user->identifier()}

Result

user0: tom
user1: jerry
user2: mike
myId: myidentifier

Raintpl3 $raintpl->assign('user', User::myInstance('myidentifier'));

{loop="$users" as $userItem}
    {$user=$userItem}
    user{$key}: {include="userIdentnfier.tpl"}
{/loop}
myId: {$user->identifier()}

Result

user0: tom
user1: jerry
user2: mike
myId: mike

This feature is not awesome(easy to bypass), but so useful to clean code. Don't need to raintpl now, but can be enhanced in future.

kargnas avatar Aug 05 '13 02:08 kargnas