How To: Button Element Dynamic Open New Tab

On a button element using Dynamic Link, how to set the Open New Tab optionall dynamically?

Where are you getting the link? A WP custom field, an ACF field?
For a button you can select dynamic data and the option ‘open in new tab’ is just there to select… bottom of this screenshot…

If you want to dynamically create the whole link, you can do:

<a href="{my_field}" target="_blank">Link</a>

If you use a PHP snippet, or wish to set the target dynamically - you need ACF Link field which lets you choose ‘new tab’, then the array element…

<?php
	$acf_row = \Bricks\Query::get_loop_object();
	if($acf_row) {
    echo '<a class="menu-link" href="' . $acf_row['menu_link']['url'] . '" target="' . $acf_row['menu_link']['target'] . '">';
    echo '<div class="menu-title">' . $acf_row['menu_link']['title'] . "</div></a>";
  }
?>

Or with bricks elements using the dynamic data array… e.g.

<a href="{my_field}" target="{my_field:array_value|target}">Link</a>

Or ‘new tab’ as a second acf field so you can do…

<a href="{my_field}" target="{other_field}">Link</a>

Despite this flexibility, it’s not possible AFAIK to just set the button dynamically… so I usually create a basic text with the link, and give it the bricks button classes.

1 Like

Hello,

That is a fantastic reply. Thank you.
Yes, I was using ACF and thanks for confirming AFAIK about setting the open new tab button control dynamically.

Hey Michael,

since version 1.8 you can use the :array_value|{KEY} dynamic data filter for this.

So if your ACF link (the field name in my example is custom_link) has a return type of Link Array you can get the link title using the following dynamic data tag:

{acf_custom_link:array_value|title}

And you can use a custom attribute to dynamically get the target attribute:

{acf_custom_link:array_value|target}

Let me know if that helps.

Best,

André

3 Likes

Awesome. Thanks André