PHP function in column template

4 posts, 0 answers
  1. Andrej
    Andrej avatar
    2 posts
    Member since:
    Sep 2019

    Posted 17 Sep Link to this post

    Hello,

    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.
  2. Tsvetomir
    Admin
    Tsvetomir avatar
    377 posts

    Posted 18 Sep Link to this post

    Hi Andrej,

    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
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  3. Andrej
    Andrej avatar
    2 posts
    Member since:
    Sep 2019

    Posted 18 Sep Link to this post

    I have tried, but approach

    #if (kendo.toString(kendo.parseDate(data.NearestTaskDate), "yyyy-MM-dd") === #=date(\'Y-m-d\')#) {#

    doesn't work.

  4. Tsvetomir
    Admin
    Tsvetomir avatar
    377 posts

    Posted 19 Sep Link to this post

    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

    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top