Get default language code - without looping?

I want to get the default language code. I can do this:

foreach(site()->languages() as $language) {
	if( $language->default() === true ) {
		$code = $language->code();
	}
}
echo $code;

It’s much overhead. Is it possible to do something like this?

echo site->defaultLanguageCode();

Here you go: https://getkirby.com/docs/cheatsheet/site/defaultLanguage

<?php $site->defaultLanguage()->code() ?>
1 Like

Oh, great! I was looking here:

https://getkirby.com/docs/cheatsheet#language

A search function for docs would be great when you are a little disorientated as me.

Thanks!

Yes, I agree, while we do have a search function, it does not necessarily unveil what you are looking for. I put that on the to do list quite some time ago …

1 Like

Ahh! I always hang on the cheatsheet page so this it the first time I saw it. It’s quite nice but as always I have some things on my mind.

  • When searching it searches live with ajax. When clicking enter that search result disapears and another search result appear with another design. It’s a little bit difficult to get back to the ajax design which is more compact.
  • I’ve never used the search box because I never hang on the docs root page. Maybe have a search on every function collection page, like toolkit and cheatsheet.
  • Exact matching is missing. This search finds many things, even things that don’t match.
  • Best matches are not in the top of the list.

I could go on. A basic search it is and it will probably help me in the future.

Thanks!

Who would have expected anything else? :stuck_out_tongue_winking_eye:

But as I said, there’s enough room for improvement …

1 Like

solved

<?php echo $kirby->language()->code(); ?>