2.x Introduce is_target_blank method for MenuItem#1701
Conversation
|
Hey @gchtr, thanks as always for the PR and tests. I'm wondering if the Item targets can now be checked with <a href="{{ item.link }}" target="{{ item.target }}">And in combination with MenuItem::is_external(): <a href="{{ item.link }}" {{ item.target is '_blank' or item.is_external ? 'target="_blank"' }}>I realize it's a small distinction, but it seems (slightly) more versatile. While I agree with @gserafini that the possibilities are pretty limited, this would eliminate the need for a conditional in menus (only requiring it if someone wanted the external or blank logic). What say you? |
|
@jarednova The only reason I didn’t choose to use <a href="{{ item.link }}" {{ item.target }}>which could add <a href="{{ item.link }}" target="{{ item.target }}">But why don’t we add both? Would we add redundancy if developers could still use <a href="{{ item.link }}" {{ item.is_target_blank or item.is_external ? 'target="_blank"' }}>And I see, before we merge this, I should probably update the menu guides and add |
|
I'm good with both! (and the gif that goes along with it). Let's do it |

Ticket: #1629
Issue
There is no easy way to check whether the «Open link in new tab» option is checked on a menu item in the backend.
Solution
MenuItem::is_target_blank()that checks whether the post meta entry_menu_item_targetis set to "blank".nullforMenuItem::meta().is_target_blank()andis_external()to use them in combination.Impact
None.
Usage Changes
Item targets can now be checked with
And in combination with
MenuItem::is_external():Testing
I added a test to check for the different states:
_menu_item_targetmeta value set on a menu item_menu_item_target._menu_item_target.