1
我有用樹枝生成的豐富文本。文本分爲兩段。 如何創建一個閱讀更多功能/按鈕,其中第一段顯示,第二個將在點擊按鈕時可見?用樹枝分割兩段文字
我想是這樣的:
{% set paragraphs = content | split('</p>') %}
{% set firstParagraph = paragraphs | first ~ '</p>' %}
{% set secondParagraph = paragraphs[:2] ~ '</p>' %}
<div class="accordion-group">
<div class="accordion-heading">
<a class="accordion-toggle custom-title" data-toggle="collapse" data-parent="#accordion2" href="#collapseTwo"></a>
<p>{{ firstParagraph | raw }}</p>
</div>
<div id="collapseTwo" class="accordion-body collapse">
<div class="accordion-inner">
<p>{{ secondParagraph | raw }}</p>
</div>
</div>
<script type="text/javascript">
$(document).ready(function(){
$('.SeeMore2').click(function(){
var $this = $(this);
$this.toggleClass('SeeMore2');
if($this.hasClass('SeeMore2')){
$this.text('{{ 'Read more' | t }}');
} else {
$this.text('{{ 'Read less' | t }}');
}
});
});
</script>
<a class="SeeMore2" data-toggle="collapse" href="#collapseTwo">{{ 'Read more' | t }}</a>
的問題是,第二段返回array
作爲響應。