Joomla 2.5呈现com_content组件输出 [英] Joomla 2.5 render com_content component output
问题描述
是否可以从外部脚本渲染Joomla内容?例如,我有一些html字符串,我希望将其传递给com_content
组件,以使所有内容插件和模块功能都可用.我想我应该使用JDocumentRendererComponent
类.我的外部文件中的代码:
is it possible to render Joomla content from external script? For example I have some html string, which I want to pass to com_content
component, to make all content plugin and module features available. I think I should use JDocumentRendererComponent
class. Code in my external file:
<?php
require_once ('framework.php'); //loading joomla framework
jimport('joomla.document.html.renderer.component');
$contentHtml = '<p>Some content html</p>';
echo JDocumentRendererComponent::render('com_content',array(),$contentHtml);
?>
我得到的是最后一行的错误:
What I get is error on the last line:
Fatal error: Class 'JDocumentRendererComponent' not found...
我做错了什么?有任何想法吗?
What Im doing wrong? Any ideas?
推荐答案
我为我的问题找到了其他解决方案.该工作还可以通过内容插件事件(触发)来完成. components/com_content/views/article/view.html.php
中的一段代码:
I found other solution for my question. The job can be also done by content plugin events (triggers). The piece of code from components/com_content/views/article/view.html.php
:
JPluginHelper::importPlugin('content');
$results = $dispatcher->trigger('onContentPrepare', array ('com_content.article', &$item, &$this->params, $offset));
$item->event = new stdClass();
$results = $dispatcher->trigger('onContentAfterTitle', array('com_content.article', &$item, &$this->params, $offset));
$item->event->afterDisplayTitle = trim(implode("\n", $results));
$results = $dispatcher->trigger('onContentBeforeDisplay', array('com_content.article', &$item, &$this->params, $offset));
$item->event->beforeDisplayContent = trim(implode("\n", $results));
$results = $dispatcher->trigger('onContentAfterDisplay', array('com_content.article', &$item, &$this->params, $offset));
$item->event->afterDisplayContent = trim(implode("\n", $results));
因此,我们实际上可以从字符串中创建一个对象,并将其传递给这些触发器.结果,我们获得的内容像文章一样具有主要功能.
So we can actually make an object from our string and pass it to these triggers. As a result we are getting content rendered like an article, with its major functionality.
有关它的更多信息:
http://www.inmotionhosting. com/support/edu/joomla-25/create-plugin/content-plugin-events https://groups.google.com/forum/# !msg/joomla-dev-cms/VZVurjiZWIs/9Vr45KS2LTMJ
这篇关于Joomla 2.5呈现com_content组件输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!