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

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}'
Reply
#2

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! ***/
Reply
#3

PHP Code:
{
    'data'data => [
        moment(data.published_date).format('DD/MM/YYYY'),
        moment(data.published_date).format('HH:mm'),
    ].reduce(
        (accvalueindex) =>
            acc.replace(`{${index}}`, value),
        data.status === 'draft' ?
            <?=json_encode(lang('blog.post.last_update'))?> :
            <?=json_encode(lang('blog.post.published_on'))?>
    )
}, 

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

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




Theme © iAndrew 2016 - Forum software by © MyBB