thkm
March 14, 2019, 4:41pm
1
Hi,
I have a problem similiar to this post and it seems that str::slug()
doesn’t work with chinese either.
So my question is, how I can use slug()
to use my default language?
I use a one pager template and my code looks like this:
<?php
$categories = $data->categories()->toStructure();
$selected = $categories->first();
?>
<ul>
<?php foreach ($categories as $category): ?>
<li class="tab <?= $category == $selected ? 'is-selected' : '' ?>">
<a href="<?= $site->defaultLanguage('en')->url() . '/#' . str::slug($category->title()) ?>">
<?= $category->title()->html() ?>
</a>
</li>
<?php endforeach ?>
</ul>
Let’s start with a little fix:
It should be
$kirby->defaultLanguage()
not $site
and the defaultLanguage()
method doesn’t accept a parameter (there is only one default language).
What is the result you get from str::slug($category->title())
?
thkm
March 14, 2019, 5:00pm
3
I’ve fixed the code
...
<a href="<?= $kirby->defaultLanguage()->url() . '/#' . str::slug($category->title()) ?>">
<?= $category->title()->html() ?>
</a>
...
I get the desired result for two languages but for the chinese I get nothing #
You probably need a custom sluggify method for Chinese. Since I’m not familiar with it at all, I can’t give advice how to create a proper slug in Chinese.