我在Opencart後台輸入Product的attribute時有換行,但店面顯示的卻沒有換行,怎麼辦?



<textarea>
HTML標籤來裝載你輸入的Product attribute,而HTML會無視textarea的換行符\n
,所以店面顯示的Product attribute沒有換行。解決辦法:將
\n
轉為HTML換行標籤<br />
;或用不會忽略\n的HTML標籤來裝載Product attribute。
我們熱心幫助無叉用的人
以下方法適用於Opencart v1.5.1.3
以下方法適用於Opencart v1.5.1.3
- 編輯[catalog/model/catalog/product.php]
- 搜尋以下程式碼:
foreach ($product_attribute_query->rows as $product_attribute) { $product_attribute_data[] = array( 'attribute_id' => $product_attribute['attribute_id'], 'name' => $product_attribute['name'], 'text' => $product_attribute['text'] ); }
- 將
$product_attribute['text']
更改為nl2br($product_attribute['text'])
。
nl2br()
是PHP函數,會在\n
之前插入HTML換行標籤<br />
。 - 編輯[catalog/view/theme/default/template/product/product.tpl]
- 搜尋以下程式碼:
<?php foreach ($attribute_group['attribute'] as $attribute) { ?> <tr> <td><?php echo $attribute['name']; ?></td> <td><?php echo $attribute['text']; ?></td> </tr> <?php } ?>
- 將
<td><?php echo $attribute['text']; ?></td>
修改為<td><pre><?php echo $attribute['text']; ?></pre></td>
。
<pre>
會保留文本中的空格和換行符號。 - 編輯[catalog/view/theme/default/stylesheet/stylesheet.css]
- 到最後一行加入以下程式碼:
.attribute tbody tr td { white-space: pre-wrap; }
white-space: pre-wrap;
會保留其套用文本中的空格和換行符號。
0 comments:
Post a Comment