Closed Sprocket closed 12 years ago
You should use the mailing-list for your questions (https://groups.google.com/group/twig-users).
I've just tried your example and indeed, it works as expected. Here is how I've passed the variables to the template:
echo $template->render(array(
'categories' => array('1'=>'fruit', '2'=>'cars'),
'products' => array(array('name' => 'apple', 'category'=>'1')),
));
Thanks, I will use the mailing list. I'm using the FuelPHP parser so that may be complicating things. Thanks again.
I'm passing two arrays to my twig template, effectively this:
$categories = array( '1'=>'fruit', '2'=>'cars'); $products = array( array('name' => 'apple', 'category'=>'1') );
How do I get twig to echo the appropriate value for the category that the products belongs? I was hoping something like this:
{% for product in products %} {{ categories[product.category] }} {% endfor %}
I appreciate this isn't perhaps the best place to post this but everything I've found elsewhere is confused and there doesn't seem to be another Twig forum. Thanks for your time.