megclaypool
9/25/2018 - 6:45 AM

Passing Gravity Forms functions as variables to Twig/Timber

[Passing Gravity Forms functions as variables to Twig/Timber]

This came up because I needed to use variables (cause we're using Pattern Lab and Timber) to call some static html in Pattern Lab and a Gravity Forms function for Timber...

It turns out that in order to render properly when passed through a variable, WP functions need to return their data, rather than echoing it. Happily, that's one of the GF function variables :)

From Gravity Forms: Embedding A Form: gravity_form( $id_or_title, $display_title = true, $display_description = true, $display_inactive = false, $field_values = null, $ajax = false, $tabindex, $echo = true );

So instead of stopping with {{ function('gravity_form', 1, false, false, false, '', false ) }}, I needed to carry on all the way to the last argument, with ('gravity_form', 1, false, true, false, '', false, false, false). Holy crap.