【发布时间】:2020-01-31 10:52:26
【问题描述】:
我有一段代码需要多次使用,但我不希望得到一个包含很多相同代码的很长的页面。
我有这段代码:
<div class="av-product-specs-list-container">
<input type="checkbox" id="chck1" checked>
<label class="av-product-specs-title" for="chck1">Algemene informatie</label>
<div class="av-product-specs-table-list first-spec-list">
<?php if( $av_merk != "" ) : ?>
<div class="av-product-specs-table-row">
<div class="av-product-specs-table-row-left">Merk</div>
<div class="av-product-specs-table-row-right">
<?php echo $av_merk; ?>
</div>
</div>
<?php endif; ?>
<?php
$av_attribute_group = $_product->getAttributes(37);
foreach ($av_attribute_group as $av_attribute_groups):
$av_attr_name = $av_attribute_groups->getName();
$av_attr_label = $_product->getResource()->getAttribute($av_attr_name)->getFrontend()->getLabel($_product);
$av_attr_value = $_product->getResource()->getAttribute($av_attr_name)->getFrontend()->getValue($_product);
if( $av_attr_value != "" ) :
?>
<div class="av-product-specs-table-row">
<div class="av-product-specs-table-row-left"><?php echo $av_attr_label; ?></div>
<div class="av-product-specs-table-row-right">
<?php
if( $av_attr_value == "Yes" || $av_attr_value == "Ja" ) : ?>
<div class="av-spec-yes"></div>
<?php elseif( $av_attr_value == "No" || $av_attr_value == "Nee" ) : ?>
<div class="av-spec-no"></div>
<?php else :
echo $av_attr_value;
endif;
?>
</div>
</div>
<?php endif; ?>
<?php endforeach ?>
</div>
</div>
我不需要创建超过 40 次这段代码,而是需要创建一个我可以调用的函数,并且只更改 $av_attribute_group = $_product->getAttributes(37);因为我需要领导不同的id。
我该怎么做?
【问题讨论】: