Wayfinder: open menu links a new window with "_blank" attribute

Hi,

I’m new to MODx and I am having some issues with Wayfinder.

I have a sidebar with a menu that I am recalling using it.

I have this Chunk:

<!-- <h3>[[*longtitle:default=`[[*pagetitle]]`]]</h3> -->
    <div class="row-fluid">
        <div class="col-md-9">
            <h1>[[*Headline]]</h1>
                [[*content]]
        </div>
        <div class="col-md-3 is-sidebar">
            <h2>Sidebar Menu</h2>
            
            [[!Wayfinder? &startId=`4` &level=`0`]]

            
        </div>
    </div>

What I would like to do is to add a “_blank” attribute to every menu entry so they will open in a new window.

How can I do it?

Thanks a lot in advance

Welcome to the Community! :blush:

Each list item of your Wayfinder call is defined in the rowTpl chunk, so you need to define this in your call to override the default:

[[!Wayfinder? 
   &startId=`4` 
   &level=`0`
   &rowTpl=`menuItem`
]]

Then create a chunk with the same name, in this case menuItem and add in the target attribute to the link:

<li[[+wf.id]][[+wf.classes]]><a href="[[+wf.link]]" title="[[+wf.title]]" [[+wf.attributes]] target="_blank">[[+wf.linktext]]</a>[[+wf.wrapper]]</li>
        

You can find more details on how to customize Wayfinder in the Docs.

On each resource you can enter the “Link Attributes” field - if you enter target="blank" in there, that will automatically make its way into the Wayfinder-generated menu ([[+wf.attributes]] in the chunk @vibedesign posted).

2 Likes