Log1x / acf-composer

Compose ACF Fields, Blocks, Widgets, and Option Pages with ACF Builder on Sage 10.
https://github.com/Log1x/acf-composer
MIT License
413 stars 56 forks source link

Equeue script depending on ACF field #144

Closed artemov-alexey closed 6 months ago

artemov-alexey commented 1 year ago

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!

kupoback commented 1 year ago

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 commented 1 year ago

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