Log1x / sage-directives

A set of Blade directives for use with Roots Sage.
https://log1x.github.io/sage-directives-docs/
MIT License
284 stars 35 forks source link

Using ACF field name as parameter to @image directive - view not being recompiled when ACF field value is updated. #117

Closed JakeJolt closed 8 months ago

JakeJolt commented 1 year ago

Hi @Log1x,

Thanks so much for your work on this, I love the simplicity of of my markup using these directives. I have an issue I’m wondering if you can help with:

I’m using the @image directive inside a blade template for an ACF block (using mwdelaney/sage-acf-gutenberg-blocks). I’m passing an ACF field name as the first argument ie. @image( 'my_image_field', 'large', ... ). Strangely, when I update the value of this field in the block editor, for example swapping an image, the view isn’t being re-compiled and I continue to see the cached view (with the old field value) when I refresh the page. After running the WP CLI command wp acorn view:clear the view is updated and displays correctly. This issue does not occur if instead of passing the field name as the first argument, I pass the value itself ie. @image( get_field( 'my_image_field' ), 'large', ... ).

I don’t know much about how views are cached in Sage and I’m struggling to find much information on it, so apologies if this isn’t actually anything to do with your code, but thought perhaps you might be able to shed some light.

Thanks a lot,

Log1x commented 1 year ago

I'm assuming something weird is happening with https://github.com/Log1x/sage-directives/blob/master/src/Directives/WordPress.php#L433 – I probably need to move the get_field() call/conditions into the Blade echo its self.

I will try to mess with it sometime this week unless you want to try your hand at a PR.

JakeJolt commented 1 year ago

Thanks for the pointer, looks like that solves it. I'll test and submit a PR.