lewisjenkins / craft-dynamic-fields

Populate Craft fields with dynamic data using the power of Twig.
Other
147 stars 11 forks source link

Dynamic Field output in twig breaks Live Preview #24

Open Tim-Wils opened 5 years ago

Tim-Wils commented 5 years ago

Outputting the field in twig breaks the Live Preview functionality and gives an error. The problem is that the field needs to be json_encoded in the Live Preview.

To workaround this problem, this is a fix on the twig-side:

{% if craft.app.request.isLivePreview %} {{ myDynamicField|json_encode}} {% else %} {{ myDynamicField }} {% endif %}