What is the proper way to call for the Content language field type. My below code works but I don't use the content language field type. I am building a drop down from all available languages.

$languages = JLanguageHelper::getLanguages();
if ($row->contentlanguage == null)
    $lang = JFactory::getLanguage();
    $selectedlanguage = $lang->getTag();
    $selectedlanguage = $row->contentlanguage;
$DropdownCode = mosHTML::selectList( $languages, 'contentlanguage', 'class="text_area" size="1"', 'lang_code', 'title', $selectedlanguage );

Joomla Field Type link: https://docs.joomla.org/ContentLanguage_form_field_type

Some Context
I have a form in a component where I want the user to select one of the Joomla installed content languages. The component base code that I am changing was not written with the XML field definitions style. And all the examples on the internet is for the XML field definitions style. Joomla has lots of field types for forms, but its always a problem getting the code not the xml for getting the Joomla field type.

The below example will generate the HTML for the date time field type of Joomla. With this question I want the same type of code for the Content Language Field type.

    $attribs['todayBtn'] = 1;
    $attribs['weekNumbers'] = 0;
    $attribs['showTime'] = 1;
    $attribs['class'] = 'inputdatetimesize';      
    return JHTML::_('calendar',$this->value, $this->name, $this->name, $this->format, $attribs);
  • Are you trying to select the language in a plugin or maybe a form in a component? A bit more context might be helpful, thanks.
    – Irata
    Jun 16, 2019 at 9:00
  • @Irata some context added. Thanks for reply.
    – Niel Buys
    Jun 16, 2019 at 11:49
  • As I understand your query is you want to render the XML defined field to be able select the Language in your components Form but you would like find the code you need around your form to make that XML defined field available to your form?
    – Irata
    Jun 17, 2019 at 12:53
  • I don't use xml at all. I need the official Joomla php code to render the Content Language Field type.
    – Niel Buys
    Jun 18, 2019 at 13:22
  • Example of what I need added to question.
    – Niel Buys
    Jun 18, 2019 at 13:36

1 Answer 1


The field uses JHtmlContentLanguage::existing() to get the languages. You can use it too.

// Get the languages.
$languages = JHtml::_('contentlanguage.existing');

// Render the dropdown.
$DropdownCode = JHtml::_('select.genericlist', $languages, 'contentlanguage', array('class' => 'text_area', 'size' => '1'), 'value', 'text', $selectedlanguage);
  • Thanks for reply @Sharky. Your code I think is the newer version as mine. But in above question I thought there would be a 1 liner getting an language dropdown. I suppose It don't exist with no other replys here.
    – Niel Buys
    Jul 11, 2019 at 7:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.