API16

Difference between revisions of "JComponentHelper/renderComponent"

From Joomla! Documentation

< API16:JComponentHelper
(New page: ===Description=== Render the component. <span class="editsection" style="font-size:76%;"> <nowiki>[</nowiki>Edit Descripton<nowiki>]<...)
 
m (preparing for archive only)
 
(2 intermediate revisions by the same user not shown)
Line 2: Line 2:
 
Render the component.  
 
Render the component.  
  
<span class="editsection" style="font-size:76%;">
 
<nowiki>[</nowiki>[[Description:JComponentHelper/renderComponent|Edit Descripton]]<nowiki>]</nowiki>
 
</span>
 
  
{{Description:JComponentHelper/renderComponent}}
+
 
 +
<! removed transcluded page call, red link never existed >
  
 
===Syntax===
 
===Syntax===
Line 102: Line 100:
 
</source>
 
</source>
  
<span class="editsection" style="font-size:76%;">
+
 
<nowiki>[</nowiki>[[SeeAlso:JComponentHelper/renderComponent|Edit See Also]]<nowiki>]</nowiki>
+
<! removed transcluded page call, red link never existed >
</span>
 
{{SeeAlso:JComponentHelper/renderComponent}}
 
  
 
===Examples===
 
===Examples===
<CodeExamplesForm />
+
=== Code Examples ===
 
<dpl>
 
<dpl>
 
  noresultsheader=\n
 
  noresultsheader=\n
 
  category=renderComponent
 
  category=renderComponent
 
  category=JComponentHelper
 
  category=JComponentHelper
  category=CodeExample
+
  namespace=CodeExample
 
  category=MethodExample
 
  category=MethodExample
 
  include=*
 
  include=*
 
  format= ,,,
 
  format= ,,,
 
</dpl>
 
</dpl>
 +
[[Category:Archived pages API16]]

Latest revision as of 20:24, 24 March 2017

The "API16" namespace is an archived namespace. This page contains information for a Joomla! version which is no longer supported. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.

Description[edit]

Render the component.


<! removed transcluded page call, red link never existed >

Syntax[edit]

static renderComponent($option, $params=array())
Parameter Name Default Value Description
$option The component option.
$params array()

Defined in[edit]

libraries/joomla/application/component/helper.php

Importing[edit]

jimport( 'joomla.application.component.helper' );

Source Body[edit]

public static function renderComponent($option, $params = array())
{
        // Initialise variables.
        $app    = JFactory::getApplication();

        if (empty($option)) {
                // Throw 404 if no component
                JError::raiseError(404, JText::_("COMPONENT_NOT_FOUND"));
                return;
        }

        $scope = $app->scope; //record the scope
        $app->scope = $option;  //set scope to component name

        // Build the component path.
        $option = preg_replace('/[^A-Z0-9_\.-]/i', '', $option);
        $file   = substr($option, 4);

        // Define component path.
        define('JPATH_COMPONENT',                               JPATH_BASE.DS.'components'.DS.$option);
        define('JPATH_COMPONENT_SITE',                  JPATH_SITE.DS.'components'.DS.$option);
        define('JPATH_COMPONENT_ADMINISTRATOR', JPATH_ADMINISTRATOR.DS.'components'.DS.$option);

        // get component path
        if ($app->isAdmin() && file_exists(JPATH_COMPONENT.DS.'admin.'.$file.'.php')) {
                $path = JPATH_COMPONENT.DS.'admin.'.$file.'.php';
        } else {
                $path = JPATH_COMPONENT.DS.$file.'.php';
        }

        // If component disabled throw error
        if (!self::isEnabled($option) || !file_exists($path)) {
                JError::raiseError(404, JText::_('COMPONENT_NOT_FOUND'));
        }

        $task = JRequest::getString('task');

        // Load common and local language files.
        $lang = &JFactory::getLanguage();
                $lang->load($option, JPATH_BASE, null, false, false)
        ||      $lang->load($option, JPATH_COMPONENT, null, false, false)
        ||      $lang->load($option, JPATH_BASE, $lang->getDefault(), false, false)
        ||      $lang->load($option, JPATH_COMPONENT, $lang->getDefault(), false, false);

        // Handle template preview outlining.
        $contents = null;

        // Execute the component.
        ob_start();
        require_once $path;
        $contents = ob_get_contents();
        ob_end_clean();

        // Build the component toolbar
        jimport('joomla.application.helper');
        if (($path = JApplicationHelper::getPath('toolbar')) && $app->isAdmin()) {
                // Get the task again, in case it has changed
                $task = JRequest::getString('task');

                // Make the toolbar
                include_once $path;
        }

        $app->scope = $scope; //revert the scope

        return $contents;
}


<! removed transcluded page call, red link never existed >

Examples[edit]

Code Examples[edit]