Mandeep Gill
Mandeep Gill

Reputation: 4895

PHP and Twig Set Variable Value

I am working with CI Framework and using Twiggy Template Engine for this. I am getting issue from last day and after do everything i couldn't found solution about how to override php array value using twig. Here is code and with this you can understand more..

$data['get_sup_sp_id'] = 6;
$data['profile'] = $this->user_model->get_sp_Profile($data['get_sup_sp_id']);

Twig Code :

{{ dump(data.profile) }}

Twig code just dump array values but i want to set according to id but not want to set static as i already.

Is there any solution in twig or twig filters with that i can set $data['get_sup_sp_id];

Thanks

Upvotes: 0

Views: 694

Answers (1)

user1777136
user1777136

Reputation: 1756

You can merge a hash (php associative array) into an existing hash like so:

{{ dump(data|merge({ 'get_sup_sp_id': 2 })) }}

See more on merging here: http://twig.sensiolabs.org/doc/filters/merge.html#merge

Upvotes: 1

Related Questions