用竖线 (|) 分隔限制器值

separate limiter values with a pipe (|)

我正在尝试弄清楚如何使用 管道 (|)

分隔限制器值

理想情况下,最终结果将是 View: 48 | 120 | ALL,目前我已经可以得到View: 48 120 ALL

这是我目前使用的:

<div class="field limiter">
    <label class="label" for="limiter">
        <span><?= /* @escapeNotVerified */ __('View:') ?></span>
    </label>
    <div class="control">
        <?php foreach ($block->getAvailableLimit() as $_key => $_limit): ?>
            <a data-role="limiter" href="#" data-value="<?php /* @escapeNotVerified */ echo $_key ?>"<?php if ($block->isLimitCurrent($_key)): ?>
                class="selected"<?php endif ?>>
                <?php /* @escapeNotVerified */ echo $_limit ?>
            </a>
        <?php endforeach; ?>
    </div>
</div>

尝试使用 PHP implode(), 检查下面修改后的代码:

<div class="field limiter">
    <label class="label" for="limiter">
        <span><?= /* @escapeNotVerified */ __('View:') ?></span>
    </label>
    <div class="control">
        <?php foreach ($block->getAvailableLimit() as $_key => $_limit): ?>
            <a data-role="limiter" href="#" data-value="<?php /* @escapeNotVerified */ echo $_key ?>"<?php if ($block->isLimitCurrent($_key)): ?>
                class="selected"<?php endif ?>>
                <?php /* @escapeNotVerified */ echo implode("|",$_limit) ?>
            </a>
        <?php endforeach; ?>
    </div>
</div>

CSS可以轻松搞定。

对于这种调整,我总是更喜欢 CSS。

.limiter .control a + a::before {
   content: " | ";
}

它将在标签之间添加管道分隔符

可在 Fiddle

找到演示

希望以上内容对您有所帮助!