data.php
$sql = 'SELECT * FROM commodity ORDER BY id ASC';
$statement = $pdo->prepare($sql);
$statement->execute();
$commodity = $statement->fetchAll(PDO::FETCH_ASSOC);
?>
<script>
var commodity = <?php echo json_encode($commodity, JSON_NUMERIC_CHECK)?>;
</script>
index.php
<?php include('data.php');?>
<div id="commodity-list">
<div class="close">x</div>
<!-- 此為商品清單Template -->
</div>
<script id="commodity-list-item-template" type="text/x-handlebars-template">
<div class="container">
<img src="{{img}}" alt="{{img}}">
<div class="content">
<div class="book-name">{{book_name}}</div>
<div class="author">作者:<span>{{author}}}/span></div>
<div class="Publishing-house">出版社:<span>{{Publishing_house}}</span></div>
<div class="Publication-date">出版日期:<span>{{Publication_date}}</span></div>
<div class="price">NT${{price}}</div>
<div class="button">加入購物車</div>
</div>
</div>
</script>