Sophat Chhay
Sophat Chhay

Reputation: 9

Echo JS variable in Joomla JText

Ajax.php, Script tag in php file

<script>
 success: function(data) {
    var message = data.message; //Json data 
    if ( data.status == 1 ) {
      jQuery("#msgError").html(<?php echo JText::_(' + message + ');?>);
    } 
 }

Is it possible to Echo JS variable in php like above?

Upvotes: 0

Views: 985

Answers (1)

Gunjan Patel
Gunjan Patel

Reputation: 144

Here is a best example,

<?php
// In php write following code
JText::script('COM_HELLOWORLD_MESSAGE');

<script>
// Using in Javascript like this
Joomla.JText._('COM_HELLOWORLD_MESSAGE')

// For your example look like
 success: function(data) {
    if ( data.status == 1 ) {
      jQuery("#msgError").html(Joomla.JText._('COM_HELLOWORLD_MESSAGE'));
    } 
 }
;
</script>

I already sent code to merge in joomla to make it more advanced. Please check it here https://github.com/joomla/joomla-cms/pull/6006 Also there are many ways to do it which you will find in above link.

Upvotes: 2

Related Questions