So for example - in the jrAudio/templates/item_detail.tpl file, you'll now see this:
{jrCore_item_detail_features module="jrAudio" item=$item}
You'll see the exact same setup in all item_detail.tpl files, for all modules. Previously we had 3 different smarty function calls in it's place (jrTags, jrComments and jrDisqus). So now, those 3 modules have registered with the core that they provide a section that can be added to the item detail page:
// We offer a module detail feature for comments
$_tmp = array(
'function' => 'jrComment_item_comments_feature',
'label' => 'Item Comments',
'help' => 'Adds User Comments to item detail pages'
);
jrCore_register_module_feature('jrCore', 'item_detail_feature', 'jrComment', 'item_comments', $_tmp);
So a module can register for the "item_detail_feature" that is provided by jrCore. You can see that a small array of info is passed in to the registration function:
function - this is the function that is to be run when your feature is called. Note that you do NOT have to check for: module being active, quota being allowed, module or item being passed in properly. When your function is called you can assume it passed these tests and can do it's work. So our jrComment module function looks like this:
/**
* Return a comment form field entry and existing comments
* @param string $module Module item belongs to
* @param array $_item Item info (from DS)
* @param array $params Smarty function parameters
* @param array $smarty current Smarty object
* @return string
*/
function jrComment_item_comments_feature($module, $_item, $params, $smarty)
{
global $_conf;
if (isset($params['template']) && $params['template'] != '') {
$params['tpl_dir'] = $_conf['jrCore_active_skin'];
}
else {
$params['template'] = "comment_form.tpl";
$params['tpl_dir'] = 'jrComment';
}
if (!isset($params['style']) || strlen($params['style']) === 0) {
$params['style'] = '';
}
if (!isset($params['class']) || strlen($params['class']) === 0) {
$params['class'] = '';
}
$_tmp = array(
'jrComment' => array(
'profile_id' => $_item['_profile_id'],
'item_id' => $_item['_item_id'],
)
);
foreach ($params as $k => $v) {
$_tmp['jrComment'][$k] = $v;
}
return jrCore_parse_template($params['template'], $_tmp, $params['tpl_dir']);
}
As you can see it simply looks for a few parameters that might have been passed in, parses the template and returns the output. There's no need to worry about smarty "assign" either - the core function also takes care of that.
So you can see it's a pretty simple setup, but it makes module development a bit easier since you do not have to know what other detail features there are in the system and add them to your item_detail template - instead you can just use the {jrCore_item_detail_features} core smarty function and know that it is taken care of. If future modules develop new features, no changes are needed to templates.
The other side to this is there is also a new Tool in the Core Tools menu called "Item Detail Features" that allows the site owner to turn on/off specific features, as well as decide what order they want them to be on the detail pages, so it's a nice setup.
So check it out and let me know if you guys have any questions or see any issues, or wonder how something works.
Thanks!
--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net
updated by @brian: 11/05/13 10:52:00PM