Return a array in Plugin function

libero - 7 months ago

I try create a Plugin. But I can't return a array to view. I think this will be solution. Below is code. public function getFunctions(){ return [ new \Twig_SimpleFunction( 'get_products', function(){ //return $this->dispatch(new \Anomaly\ProductsPlugin\Products\Command\GetMenuView); $url = 'http://qa.p16011.dsquare.vn/umbraco/Surface/Service/Product'; $json_string = file_get_contents($url); $json = json_decode($json_string, true); //return $json_string; return $this->view->make('anomaly.plugin.products::menu/getproduct', compact('json')); }) ];

ryanthompson - 7 months ago

I can't make heads or tails of that code - can you format it for us all?

If you dd($value) in your plugin return and it's an array.. that's what's being sent back to the view. Pretty straight forward at this point cause Twig compiles to PHP so arrays are arrays (nothing fancy going on).