I think the “isOpen” only works with “<?php foreach ($site->children()->listed() as $item): ?>” right?
How is it possible to highlight an active link when i use a structured field?
Well, unfortunately you didn’t post your structure field, but for the actual page links, you can convert the field value to page with toPage(). For this object you can then test if the item is open.
If the value is just a string, it really depend to which page they actually link. Is it just a URL in that case?
Otherwise, you would have to check the URL to determine which link is active.
I’m afraid I don’t quite understand the question. Url::current() is a method (not an object) that is just used like that, no params, no nothing., so you just echo it (or use it for comparisions):
<?= Url::current() ?>
and will return the current Url (with query strings or params etc. if applicable)
Could you please provide more context. The original TO asked about structure field items… What would be your equivalent to a parent page in this context? what is $item?
One level, not nested. The code below works fine when on the actual page, but the active state does not remain when drilling down into a section. For example, /works vs /works?filter=Residential
Really sorry, maybe we have a wording problem here. Your example uses a url query string, that cannot possibly work when you compare a nomal page link with Url::current() which returns exactly a Url with the query string included.
Don’t think there is a method for that, you either have to construct it from the uri object, or use
$_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']
Not sure what you mean by “drilling down into a section”.
If you are using only pages as links, you could compare to the current $page->url(), if you are only dealing with pages, you could also convert the stored UUID to a page object, which would allow you to use $page->isActive() and isOpen
Using isOpen() on a normal menu using pages will set the link active no matter what level you’re at. For example:
/projects
/projects/project-name
…but with a mixed link structured menu, there’s no way to do it. Using Url::current() only sets the link active at the top level /projects, similar to how isActive() works on normal menus.