PHP Integration - add custom twig functions and filters

There is a way to add custom twig functions and filters.

This functionality is available in PRO verison only.

So, in functions.php or in some snippet you enter this code: 

/**
 * custom twig function
 */
function myTwigFunction(){
	
	echo "Custom function is working great!!!";
	
}

/**
 * custom twig filter
 */
function myTwigFilter($text){
	
	return($text."... custom filter is working great!!!");
}

/**
 * add twig function
 */
function addMyTwigFunctionality($twig){

	$twig->addFunction(new Twig_SimpleFunction("myFunction", "myTwigFunction"));	
	$twig->addFilter(new Twig_SimpleFilter("myFilter", "myTwigFilter"));
}

add_action("unlimited_elements/twig/add_custom_features", "addMyTwigFunctionality");

In this code we created custom twig function and custom twig filter.

In the widget editor you can use them like this: 

  {{myFunction()}}
  {{uc_id|myFilter}}
  
More info about how to create twig functions and filters you can find here: 
Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.