Posting list items into code that varies

7 posts by 2 authors in: Forums > CMS Builder
Last Post: July 15, 2016   (RSS)

By Toledoh - July 14, 2016

That looks like a standard bootstrap accordion to me?  If so, so this code - just match your field names:

<?php

// load records from 'facts'
list($factsRecords, $factsMetaData) = getRecords(array(
'tableName' => 'facts',
'loadUploads' => true,
'allowSearch' => false,
));

?>
<?php $count = 0 ?>
<div class="panel-group" id="accordion">
<?php foreach ($factsRecords as $record): ?>
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title" style="color: #000;">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion" href="#collapse<?php echo htmlencode($record['num']) ?>">
<?php echo htmlencode($record['title']) ?>
</a>
</h4>
</div>
<div id="collapse<?php echo htmlencode($record['num']) ?>" class="panel-collapse collapse<?php if (!$count): ?> in<?php $count++ ?> <?php endif ?> ">
<div class="panel-body">
<?php echo htmlencode($record['content']) ?>
</div>
</div>
</div>
<?php endforeach ?>
</div>

Cheers,

Tim (toledoh.com.au)

By superhappybunnycat - July 15, 2016

Excellent thank you! Great idea to use the number field for the variable.

Only issue I am seeing now is the answer content is showing <p> <span style="color: #00ccff;"> etc within it instead of changing the style of the text. Is there any reason this is happening?

By Toledoh - July 15, 2016

Nah - that's just my stuff up.  Just delete it.

Cheers,

Tim (toledoh.com.au)

By superhappybunnycat - July 15, 2016

From where though? It's not coming from your code. The answer field is a WYSIWYG field - it's coming from CMSB

By Toledoh - July 15, 2016

Sorry - just change <?php echo htmlencode($record['content']) ?> to <?php echo ($record['content']) ?>

Also, remove the extra styling here: <h4 class="panel-title" style="color: #000;">

Cheers,

Tim (toledoh.com.au)

By superhappybunnycat - July 15, 2016

That did the trick! Thanks so much for your help with this :)