sylvainjule / kirby-pagetable

Display subpages in a flexible table section. Kirby 3 only.
MIT License
113 stars 11 forks source link

field method multi catergories #9

Closed gfxdude-dus closed 5 years ago

gfxdude-dus commented 5 years ago

is it possible that you give me a small hint on how to edit the field method for multi categories? thanks!

sylvainjule commented 5 years ago

How does your field look like in the .txt, and how would you like to have it displayed?

gfxdude-dus commented 5 years ago

.txt: Category: Food, Sport, Nature

my idea is to render each value in its own span with its own class and style. trying to explode and split but can't get it to work.....lack of devskills :-/

sylvainjule commented 5 years ago

You can try something like:

$categories = $field->split(',');
$wrappedCategories = array_map(function($category) {
  return '<span class="category-label" data-category="'. $category .'">' . $category . '</span>';
}, $categories);

return implode('', $wrappedCategories);
gfxdude-dus commented 5 years ago

Within the toLabel function? running into an error then: call to a member function split () at string

sylvainjule commented 5 years ago

My bad, get rid of ->value before split. Fixed above.

gfxdude-dus commented 5 years ago

works like a charm now! thanks a lot!