Fluent: Get "page_by_lang" functionality for templates

Silverstripe Version: 4.5


Inside my Footer Template I list serveral pages.
I would like to control them with a similar method/synatx like in SilverStripe 3.

Basically a function which accepts the UrlSegment and the Locale.

<% with $page_by_lang("home", "de_DE") %>
<% end_with %>

I am struggeling with fluent to achieve this.

Thanks for any help.

I managed it. For anyone in the same situation:

public function PageByLang($urlSegment, $locale)
    return FluentState::singleton()->withState(function (FluentState $newState) use ($urlSegment, $locale) {
        $page = SiteTree::get()->filter([
            'URLSegment' => $urlSegment

        return SiteTree::get()->byID($page->ID);