Welcome Guest, Not a member yet? Register   Sign In
How to pass parameters to lang from js?

In one of my DataTable column I have this code:

PHP Code:
    'data': function(data) {
             let date moment(data.published_date'DD/MM/YYYY');
             let hour moment(data.published_date'HH:mm');

             if (data.status === 'draft') {
                return "<?= lang('blog.post.last_update', [date hour]) ?>";
             } else if (data.status === 'published') {
                return "<?= lang('blog.post.published_on', [date, hour]) ?>";

I'm looking for a way to pass date and hour as lang parameter, infact in my localization I have this:

PHP Code:
        'published_on'      => 'Published {0} on {1}'

You can't do this like that. PHP run on the server, it send the final HTML document to the browser, then the JavaScript code run in the browser. So your JS code can't send parameter to a PHP function.
CodeIgniter 4 tutorials (EN/FR) - https://includebeer.com
/*** NO support in private message - Use the forum! ***/

PHP Code:
    'data'data => [
        (accvalueindex) =>
            acc.replace(`{${index}}`, value),
        data.status === 'draft' ?
            <?=json_encode(lang('blog.post.last_update'))?> :

This might work. It's not clear what format data.published_date is in.

I think you should use AJAX post method if you want to send something from JS to server.

Theme © iAndrew 2016 - Forum software by © MyBB