acf-composer icon indicating copy to clipboard operation
acf-composer copied to clipboard

Equeue script depending on ACF field

Open artemov-alexey opened this issue 2 years ago • 2 comments

Hello! Is there a way to decide inside of enqueue() method eather to enqueue 3rd party script or not depending on the value of ACF true/false field in block? We have a custom form block, so if the field is set to TRUE we want the js script to be enqueued in enqueue() method. Here is example what's needed but doesn't work because get_field returns null in enqueue():

public function enqueue(): void
    {
        $chilipiper = (bool) get_field('chilipiper');
        if (true === $chilipiper) {
            wp_enqueue_script('chilipiper-lib');
            bundle('chilipiper')->enqueue();
        }
    }

Thanks in advance!

artemov-alexey avatar Dec 06 '22 11:12 artemov-alexey

Hello! Is there a way to decide inside of enqueue() method eather to enqueue 3rd party script or not depending on the value of ACF true/false field in block? We have a custom form block, so if the field is set to TRUE we want the js script to be enqueued in enqueue() method. Here is example what's needed but doesn't work because get_field returns null in enqueue():

public function enqueue(): void
    {
        $chilipiper = (bool) get_field('chilipiper');
        if (true === $chilipiper) {
            wp_enqueue_script('chilipiper-lib');
            bundle('chilipiper')->enqueue();
        }
    }

Thanks in advance!

If you find a way to get the values from a get_field, please let me know. I am encountering the same issue.

https://github.com/Log1x/acf-composer/issues/143

kupoback avatar Dec 20 '22 19:12 kupoback

The commit that codepuncher has put in does in fact work to allow me to fetch block data.

kupoback avatar Jan 30 '23 17:01 kupoback