Menu Loop - Menu Item CSS classes

Hey, I’m trying to output the classes of a menu item in a menu loop, but couldn’t find anything about it in the documentation. I tested it with {Field class} and {Field classes}.
{Field class} does nothing at all, but {Field classes} seems to retrieve the classes correctly, however they are output with quotes and commas, e.g. [“menu-item–cta”]

You could get around the formatting problem by outputting the values as a list loop and saving it as a variable. So something like this:

<ul>
	<Loop type=menu menu="main">
	
		<If list="{Field classes}" any_is_not value="">
			<Set local=menu_item_classes><Loop list="{Field classes}"> <Field /></Loop></Set>
		<Else />
			<!-- Set empty variable to avoid unwanted spaces if the item has no classes -->
			<Set local=menu_item_classes></Set>
		</If>
	
		<li class="menu-item{Get local=menu_item_classes}">
			<a class="menu-link" href="{Field url}" target="{Field target}">
				<div><Field title /></div>
			</a>
		</li>
		
	</Loop>
</ul>

Actually this works fine, but since this seems a bit inconvenient overall, I wanted to ask if I’m missing something here or if there is an easier way to output the classes correctly?

The new Format tag attribute join can help.

<Format list join=" "><Field classes /></Format>

Could be more convenient if there was a shortcut:

<Field classes join=" " />
3 Likes