0

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

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

6 Comments

Thanks i did same but getting error : Fatal error: Uncaught exception 'Twig_Error_Runtime' with message 'The merge filter only works with arrays or hashes in "main.html.twig" at line 61.' in
Not sure what exactly you´re trying to do, maybe you want to merge the value into the data array instead of into the data.profile? So that would be data|merge({ ... })
I want to update profile according to id using get_sp_Profile php function but this function have parameter and i am using framework so i can't write twig filter to get values. Final thing i want to override $data['get_sup_sp_id'] = 6; using twig ex: {{ data.get_sup_sp_id = 2 }}
I updated my answer with a solution to how to change the get_sup_sp_id value. however, the change to the array will likely run after the call to your user_model, so this will not change the profile data.
Thanks it's worked but showing lots of data because of dump and when i use without dump it just shows array.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.