Support » Plugin: Timber » Deprecated Elements constantly throwing errors

  • Twig/Timber framework dumped on us by graphic designers. Server is constantly generating errors about ‘function_wrapper is deprecated and will be removed in 1.4’.

    No documentation at all at twig.sensiolabs.org. No search on the page at twig.sensiolabs.org. Downloaded PDF, function_wrapper is not even documented.

    Terrible framework for text-based maintenance too. Save me from the drag and drop geniuses.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hey @msarns

    The function_wrapper function is not a feature of Twig itself, but rather an extension of Timber. That’s why you didn’t find anything about it in the Twig Documentation.

    It was used to make PHP functions available when working in Twig files and was deprecated, because it was necessary only in earlier versions of Timber. Now, there are other ways to call PHP functions from Twig or make functions available to Twig. You can find a documentation for this in the Functions Guide of the Timber Documentation.

    To make the warnings go away, you will have to replace every occurrence of function_wrapper in your theme by either using {{ function('function_you_want_to_call') }} directly in your Twig file or using the timber/twig filter to add a new function to the Twig Environment.

    Okay, Replacing the only instance:

    $context[‘ninja_forms_display_form’] = TimberHelper::function_wrapper( ‘ninja_forms_display_form’ );

    with

    $context[‘ninja_forms_display_form’] = TimberHelper::{{ function(‘ninja_forms_display_form’) }};

    Yields:

    ‘Parse error: syntax error, unexpected ‘{‘ in C:\Shares\…\page.php on line 84’

    So very simple, except it does not work. I’ve been trying variations on this for another 2 hours because you said it would work. Checking the link to Function Guide I see the example for how to add a function to the ‘context’ is:

    $context[‘my_custom_function’] = new FunctionWrapper( ‘my_custom_function’, $array_of_arguments );

    Which is exactly what I’ve got, which is throwing the error.

    Yeah, it could be a little confusing first. When you use {{ function('function_you_want_to_call') }}, you can put this directly into your Twig file.

    I guess somewhere in a Twig file in your theme you do something like this:

    {{ ninja_forms_display_form(4) }}

    You can replace this with:

    {{ function('ninja_forms_display_form', 4) }}

    The first argument of function() is always the name of the function to call, followed by all the arguments you need to pass. In this example, you’d have to replace the 4 with whatever argument you used before.

    You can then delete

    $context['ninja_forms_display_form'] = TimberHelper::function_wrapper( 'ninja_forms_display_form' );

    from your PHP file. You don’t need it anymore.

    I hope this clears things up.

    • This reply was modified 6 months, 1 week ago by  gchtr.

    Thanks, giving up on getting the variable from the context and the options that were set up and instead putting the value in directly in the file got it to display. There’s only one form in the whole site setup, so that was probably some unnecessary elegance. I’ve cut the function call and there are now no errors.

    Works. Thanks.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Deprecated Elements constantly throwing errors’ is closed to new replies.