Combining 'Multiselect Plugin' with 'Related Posts'

Hi,

im using a Blog on my Webseit with Kirby. Now i want to display ‘related Posts’ in a Sidebar, wich should be defined in the Panel. So far no Problem:

In the Blueprint:

  related:
    label: Ähnliche Artikel
    type: textbox

And in my Template:

<?php if(!$page->related()->empty()): ?>
<div class="relatedposts">
<h2><i class="metaicon icon-news"></i> Ähnliche Artikel</h2>
<ul>
  <?php foreach($page->related()->pages() as $item): ?>
  <li>
    » <a href="<?php echo $item->url() ?>">
      <?php echo $item->title()->html() ?>
    </a>
  </li>
  <?php endforeach ?>
</ul>
<?php endif ?>
</div>

That works just great if i type manually all URLs in the Textfield, eg:

- blog/content-management-systeme-erfolg-fuer-ihre-website
- blog/start-des-blogs

Quite annoying and not very userfriendliy… So i found the Multiselect Plugin. Implementing the Plugin worked without any Problems, BUT: The Plugin doesnt save the URLs ob the selected in the right way…

It saves:

URL, URL, URL, URL

How can i change this format in

- URL
- URL
- URL

?

Thanks in advance :slightly_smiling:

Chris

Hi Chris,

this looks like a perfect use case for the “str::split” function: http://getkirby.com/docs/toolkit/api/str/split

I haven’t tested it with the multiselect field, but this should work too and is even simpler: http://getkirby.com/docs/cheatsheet/field-methods/split

Best,
Thomas

1 Like