I am using Telerik UI for PHP Grid component. And I want to use PHP function in column template, for ex.:
#if (kendo.toString(kendo.parseDate(data.NearestTaskDate), "yyyy-MM-dd") === date(\'Y-m-d\')) {#
<div class="feed image">
<i class="#:NearestTaskTypeIcon# icon bg-yellow"></i>
</div>
where date is PHP function. However, browser console message says that date is not defined. How can fix it? Thank you.
4 Answers, 1 is accepted
Generally, the functions within the PHP template have to be set up with the "#=#" syntax. So invoking a function would be something similar to:
#= someFunction(args) #
Give this suggestion a try and let me know how it works out for you.
Best regards,
Tsvetomir
Progress Telerik

I have tried, but approach
#if (kendo.toString(kendo.parseDate(data.NearestTaskDate), "yyyy-MM-dd") === #=date(\'Y-m-d\')#) {#
doesn't work.
Hi Andrej,
Generally, the logic executed in PHP is on server-side. While the templates of the Kendo UI are evaluated on the client-side. Therefore, the date() function has to be in a script block, placed after the <?php . . . ?> block. Here are the relevant code snippets:
$contactName->field('ContactName') ->template("#=foo()#") ->title('Contact Name') ->width(240);
And the template:
<script>
function foo()
{
return "Lorem Ipsum";
}
</script>
I am attaching the whole file to my response, for your reference.
Best regards,
Tsvetomir
Progress Telerik

Hello Friends, This is the right coding id you're create PHP function in column template. you can try this.
<?php /** * Simple Templating function * * @param $file - Path to the PHP file that acts as a template. * @param $args - Associative array of variables to pass to the template file. * @return string - Output of the template file. Likely HTML. */ function template( $file, $args ){ // ensure the file exists if ( !file_exists( $file ) ) { return ''; } // Make values in the associative array easier to access by extracting them if ( is_array( $args ) ){ extract( $args ); } // buffer the output (including the file is "output") ob_start(); include $file; return ob_get_clean(); }
Hello, Vishal,
Thank you for sharing your solution with the rest of the community!