Element condition: comparison method?

Hi there,

i have a condition on an element that compares a dynamic data tag called {acf_news_links_downloads} against being NOT EMPTY.

The dynamic data tag is built in a function which calls an ACF field, checks for its appearance and returns an empty string if ACF field is empty:

 $rows = get_field('news_downloads', $post_id); // repeater

 if (empty($rows) || !is_array($rows)) {
   return ''; // also tried returning false or explicit null but had no effect
 }

Condition on element is this:

I’m wondering what matches this condition?
is_empty(), isset(), not null, not false?

The element is shown regardless of the function return value.

Any help is appreciated!

Without the complete code that registers the DD tag, we can only guess. For starters, try removing the acf_ prefix from the tag name, as it’s probably reserved for the native ACF provider.

You can also try dropping your DD tag into a Basic Text element to see if it resolves there.

Hi,
thanks for the reply.

Since my post contains all necessary information, I could indeed post the complete code, but at this point, that is neither necessary nor helpful.

I am sure that a tag named {acf_news_links_downloads} is not reserved by ACF.
My the tag is already placed in a basic text area.

I asked for the comparison method (and the matching type) behind the element condition to know if it matches against an empty string or e.g. isset() or even both.

I was wondering if my function has to return nullor an empty string to run into that condition – like mentioned i’ve tried several values but without success.

It may be not reserved in the textarea content, but may be otherwise in the dynamic condition.

Also, have you tried testing changing the “null” value to something like “nobananas”) and setting the condition to check for that something?

Thanks for the reply.

It is surely not reserved by ACF.

I don’t get what you’ve meant by being reserved otherwise in the condition – a tag with a key name matched uniquely to its usage is not reserved since it just won’t make any sense.

Btw i was asking what exactly triggers the bricks condition setting – and basically if a return value has to be null or an empty string:

I’m wondering what matches this condition?
is_empty(), isset(), not null, not false?


Also, have you tried testing changing the “null” value to something like “nobananas”) and setting the condition to check for that something?

Since you were asking, I tested against all thinkable values to run into a true case, so: yes.

according to my experience bricks twigs dont work the same way in every condition, as an example when used within form submit options. At the point you are checking the condition the context might be different than within a textarea.

Would you then share a simple version of your twig shortcode and a minimal version of the template you are using?

Btw i was asking what exactly triggers the bricks condition setting

From includes/conditions.php line 1193: $render_set = (string) $value !== ‘’;

I am sure that a tag named {acf_news_links_downloads} is not reserved by ACF.

True, it’s not reserved by ACF, but it could be “reserved” by Bricks in the sense that Bricks expects to use its own DD for tags beginning with “acf_”. Just don’t use it for your own DD tag.

Additionally, I don’t know how you can be sure it’s not reserved (implying you have studied the code closely) and also not know how to find the answer to your initial question. :thinking:

Yup. And aljazbz wrote for the native ACF provider, meaning the provider handling bricks acf dynamic data and rightfully pointed at removing the acf_ prefix from the tag name.

But ig we should just wait for the code now.

Thats what I was asking for: it tests against an empty string.

case 'empty_not':
	$render_set = (string) $value !== '';
	break;

That means, if a function e.g. returns falseor null this case would NOT return true.
But in case of Array()or [] (empty array) the condition will return true – since it’s not empty (an Array item but without values and the warning Array to string conversion).


Additionally, I don’t know how you can be sure it’s not reserved (implying you have studied the code closely) and also not know how to find the answer to your initial question. :thinking:

Look, I know that bricks already uses an internal tag {acf_field_name} to read values ​​directly from ACF (where field_name would be the ACF field key).

My code reads a key that doesn’t exist in any of my ACF fields – that’s why I’m sure it’s not used by bricks´ built-in method.
As long as you control the field names and its exact keys, there will be no conflict.
You’re right it might be ‘cleaner’ to change the prefix but technically it does no harm.


Since you guys were asking for the code, here’s an excerpt of it.
If you look closely, you’ll recognize, that

  • '{acf_news_links_downloads}' is just a string key matched against, so…
  • …bricks´ internal mapping would look for an ACF field named news_links_download
  • in get_field('news_downloads', $post_id); you see that my field key is named news_downloads (here: a repeater field)
add_filter('bricks/dynamic_data/render_content', function ($content, $post, $context) {
  $post_id = is_object($post) ? $post->ID : (int) $post;

  if (get_post_type($post_id) !== 'jobs') {
    $queried_id = get_queried_object_id();
    if ($queried_id && get_post_type($queried_id) === 'jobs') {
      $post_id = $queried_id;
    }
  }

  // here is where it's getting interesting...
  $replacements = [
    '{acf_news_links_phone_href}'      => function () use ($post_id) {
      $tel = get_field('news_links_phone', $post_id);
      if (empty($tel) || ! is_string($tel)) {
        return '';
      }
      return esc_attr('tel:' . fn_format_phone_number($tel));
    },
    '{acf_news_links_phone_text}'      => function () use ($post_id) {
      $tel = get_field('news_links_phone', $post_id);
      if (empty($tel) || ! is_string($tel)) {
        return '';
      }
      return esc_html($tel);
    },
    '{acf_news_links_email_href}'    => function () use ($post_id) {
      $email = get_field('news_links_email', $post_id);
      if (empty($email) || ! is_string($email)) {
        return '';
      }
      return esc_attr('mailto:' . sanitize_email($email));
    },
    '{acf_news_links_email_text}'    => function () use ($post_id) {
      $email = get_field('news_links_email', $post_id);
      if (empty($email) || ! is_string($email)) {
        return '';
      }
      return esc_html($email);
    },

    '{acf_news_links_downloads}'      => function () use ($post_id) {
      $rows = get_field('news_downloads', $post_id); // repeater

      if (empty($rows) || !is_array($rows)) {
        return '';
      }

      $items = '';

      foreach ($rows as $index => $row) {
        $file_field   = $row['news_downloads_file'] ?? '';
        $url_external = $row['news_downloads_file_url_ext'] ?? '';
        $url_external = is_string($url_external) ? $url_external : '';

        // internal OR external url is mandatory
        $has_internal = ! empty($file_field);
        $has_external = $url_external !== '';

        if (! $has_internal && ! $has_external) {
          continue;
        }

        $label = ! empty($row['news_downloads_text']) && is_string($row['news_downloads_text'])
          ? $row['news_downloads_text']
          : ($has_internal
            ? basename(is_array($file_field) ? ($file_field['url'] ?? '') : (string) $file_field)
            : basename($url_external));

        $token = fn_make_download_token($post_id, $index);

        $download_url = add_query_arg([
          'fn_download' => 1,
          'post_id'        => $post_id,
          'row'            => $index,
          'token'          => $token,
        ], home_url('/'));

        $items .= sprintf(
          '<li class="news-links-download-item"><a href="%s" class="news-links-download-link">%s</a></li>',
          esc_url($download_url),
          esc_html($label)
        );
      }

      if (empty($items)) {
        return '';
      }

      return '<ul class="news-links-downloads">' . $items . '</ul>';
    },
  ];

  foreach ($replacements as $tag => $callback) {
    if (strpos($content, $tag) !== false) {
      $content = str_replace($tag, $callback(), $content);
    }
  }

  return $content;
}, 10, 3);


But you know what – simply removing the textarea element from the page structure and re-adding it (with the same tag {acf_news_links_downloads}) solved the problem. WTF :face_with_crossed_out_eyes: