HELLO I am trying to create a foreach loop which will cycle through a given list of magento products to get their attributes in order to populate a JW Player playlist. The structure of JW Player's syntax allows for the inclusion of multiple product attributes values to build a playlist, however I need to break into the foreach when it reaches the final item in order to close the playlist config.
When not being dynamically generated, the JW Player syntax looks so:
<script type="text/javascript">
jwplayer('media1').setup({
'flashplayer': 'mediaappearance/jwplayer.flash.swf',
'width': '700',
'height': '400',
playlist: [{
file: 'video for magento product 1',
image: 'image for magento product 1',
title: 'name for magento product 1',
description: 'description for magento product 1'
},{
file: 'video for magento product 2',
image: 'image for magento product 2',
title: 'name for magento product 2',
description: 'description for magento product 2'
}]
});
</script>
With this products collection, I want to get attributes for each product to populate the playlist:
<div id="tab-one" class="tabset_content">
<?php
$productCollection = Mage::getModel('catalog/product')->getCollection();
$product_file = $item->getMediaUrl();
$product_name = $item->getName();
$product_img = Mage::helper('catalog/image')->init($_product, 'small_image')->resize(113, 113);
$product_description = Mage::helper('catalog/output')->productAttribute($product, $product->getShortDescription(), 'short_description');
?>
<?php foreach ( $productCollection as $_product ) : ?>
<div class="casestudies">
<div class="jwbox" style="cursor: pointer;">
<div class="jwbox_hidden">
<div class="jwbox_content">
<div id='media1'></div>
<script type="text/javascript">
jwplayer('media1').setup({
'flashplayer': 'mediaappearance/jwplayer.flash.swf',
'width': '700',
'height': '400',
<?php
$playlist = array();
foreach($productCollection as $_product) {
$playlist = array();
$playlist[] = array(
'file' => $product_file ,
'title' => $product_name,
'image' => $product_img,
'description' => $product_description
);
echo json_encode($playlist);
}
?>
});
</script>
</div>
</div>
</div>
</div>
<?php endforeach; ?>
But the foreach loop show only 1 product attributes. I want it show for all products in the array $productCollection . Help please.