Nabeel Basheer
Nabeel Basheer

Reputation: 75

Is it possible to echo any variable inside JText::_ if so how

Is it possible to print a variable inside the JText

ie:- i need to print $email to test whether it is nil or has value in it...

$this->setMessage(JText::_('COM_USERS_REGISTRATION_ACTIVATE_SUCCESS'));

Upvotes: 2

Views: 5369

Answers (3)

di3sel
di3sel

Reputation: 2012

And if you want to use variable in the middle of string or few variables, here's an example for that:

$this->setMessage(JText::sprintf('COM_USERS_REGISTRATION_ACTIVATE_SUCCESS', $name, $email);

And in language file:

COM_USERS_REGISTRATION_ACTIVATE_SUCCESS="Hello %s, your email is: %s"

So the final output will look ($name and $email will be replaced by variable values given):

Hello $name, your email is: $email

Upvotes: 6

ghbarratt
ghbarratt

Reputation: 11711

The JText class has a static method '_' which converts the string argument passed into it into another string, using the language files and settings appropriate for the context. If you want to see what is being passed to setMessage you could just try:

echo 'DEBUG setMessage argument: "'.JText::_('COM_USERS_REGISTRATION_ACTIVATE_SUCCESS').'"';

If you find that this reveals that _ is returning nothing, then it is likely an indication that there is not an entry for 'COM_USERS_REGISTRATION_ACTIVATE_SUCCESS' in the language file(s) being used.

EDIT:

If you need to append $email then just do this:

$this->setMessage(JText::_('COM_USERS_REGISTRATION_ACTIVATE_SUCCESS').$email);

Upvotes: 0

MrCode
MrCode

Reputation: 64536

COM_USERS_REGISTRATION_ACTIVATE_SUCCESS is being replaced by a language definition of the message. If you break that up, Joomla won't recognise it.

You can append variables to that message if you want:

$this->setMessage(JText::_('COM_USERS_REGISTRATION_ACTIVATE_SUCCESS') . $email);

Or even omit JText if you need to

$this->setMessage('some message, email: ' . $email);

Upvotes: 0

Related Questions