9

我在自己的组件(view.html.php)中有视图(前端):

class MevViewMev extends JView{
        function display($tpl = null){
                parent::display($tpl);
        }
}

和模板:

<?php defined('_JEXEC') or die('Restricted access'); ?>
<div>
ASFADSFDSF
</div>

如何在没有 joomla 模板(头部、样式等)的情况下显示它。我想在窗口中调用 jquery onclick 方法的这一部分。

4

3 回答 3

21

要显示组件,只需将“tmpl=component”参数添加到 url。如果需要显示组件视图之外的其他内容,则可以对其进行自定义 - 在模板的根文件夹中创建“component.php”文件并在其中包含您需要的任何内容。更多模板可以用相同的方式完成——在模板的根文件夹中创建“some_template.php”并将“tmpl=some_template”参数添加到url。

于 2011-12-17T16:42:08.267 回答
4

开始编辑

好的,所以下面的工作,但我找到了一个更好的方法。在你的控制器做...

if (JRequest::getVar('format') != 'raw') {
    $url = JURI::current() . '?' . $_SERVER['QUERY_STRING'] . '&format=raw';
    header('Location: ' . $url);
    // or, if you want Content-type of text/html just use ...
    // redirect($url);
}

结束编辑

您可以按照 Babur Usenakunov 的建议将“tmpl”设置为“组件”,在这种情况下,可能会加载脚本和 css,例如...

JRequest::setVar('tmpl','component');

但是,如果您想创建原始输出,您可以添加 &format=raw 或在您的组件中创建 'raw' 类型的视图 ...

不幸的是,我能找到正确制作原始渲染视图类型的唯一功能方法是在视图类调用 parent::display() 之后调用 exit() ...

在你的controller.php ...

class com_whateverController() extends JController
{
    function __construct()
    {
        // the following is not required if you call exit() in your view class (see below) ...
        JRequest::setVar('format','raw');
        JFactory::$document = null;
        JFactory::getDocument();
        // or
        //JFactory::$document = JDocument::getInstance('raw');
        parent::__construct();
    }

    function display()
    {
        $view = $this->getView('whatever', 'raw');
        $view->display();
    }

}

然后在views/whatever/view.raw.php ...

class com_whateverViewWhatever extends JView
{
    public function display($tpl = null)
    {
            parent::display();
            exit; // <- if you dont have this then the output is captured in and output buffer and then lost in the rendering
    }
}
于 2013-10-22T17:26:37.790 回答
0

我知道这很晚了,但对于未来的读者来说,这是我为我的扩展做的,没有编辑模板,或者在 URL 中添加任何东西(因为我无法控制这两者):

jimport('joomla.application.component.view');
use \Joomla\CMS\Factory;

// Comp stands for the Component's name and NoTmpl stands for the View's name.
class CompViewNoTmpl extends \Joomla\CMS\MVC\View\HtmlView {

// Force this view to be component-only
public function __construct() {
  $app = Factory::getApplication();
  $app->input->set('tmpl', 'component');
  parent::__construct();
}
于 2019-11-08T09:49:39.050 回答