【发布时间】:2014-03-04 19:25:27
【问题描述】:
请告诉我如何从自定义模板中包含帮助文件?
例如,我想从 /modules/mod_breadcrumbs/helper.php 获取 ModBreadCrumbsHelper 类
在自定义模板/templates/test/html/com_content/article/default.php中
【问题讨论】:
请告诉我如何从自定义模板中包含帮助文件?
例如,我想从 /modules/mod_breadcrumbs/helper.php 获取 ModBreadCrumbsHelper 类
在自定义模板/templates/test/html/com_content/article/default.php中
【问题讨论】:
添加文件有一种“核心”方式。
JLoader::register('MyHelperClass', JPATH_ROOT . '/modules/mod_breadcrumbs/helper.php');
【讨论】:
您可以使用 include() 或 include_once() 来实现这一点。
http://us2.php.net/manual/en/function.include.php
http://us2.php.net/manual/en/function.include-once.php
示例:(在 /templates/test/html/com_content/article/default.php 内)
include "/modules/mod_breadcrumbs/helper.php"; // provided the directory "modules" is inside the directory containing "default.php"
$class = new ModBreadCrubmsHelper();
$class->stuff();
【讨论】:
jdoc:include 用于指示 Joomla 其他部分或其扩展的输出应放置在整个网页中的位置。您将在模板 index.php 文件中看到诸如 <jdoc:include type="component" /> 之类的内容,它指示输出组件的位置等。要包含帮助文件,请使用 Jonny 回答中的方法