Hello,
I have something like this in a public custom module. The goal is to read the current group of the resource presented to the user, check its custom fields for a enable/disable checkbox, and include a script if enabled.
public function onOutput($buffer) { // on page output
global $_LW;
// make group id available, continue if defined
$_LW->applyPageAndGroupVars('<xphp var="group_id"/>');
if (!empty($GLOBALS['group_id'])) {
// obtain custom fields for the current group
$fields = $_LW->getCustomFields('groups', $GLOBALS['group_id']);
/* Check to include Feature */
// get custom field value to determine if should include
$enable = ($fields['enable_feature'] === "True") ? true : false;
// if should show, then append
if ($enable) {
$buffer=str_replace('</head>', '<script type="text/javascript" src="/feature.js" defer></script></head>', $buffer);
}
}
return $buffer;
}
The intent of this resource was to only display on pages. Instead, I’ve found it appearing on stories and profiles as well.
How can I best filter behavior in the custom module based on the content type being shown? For instance, how can I narrow this down to only apply to pages, or to just stories, etc?
I know there’s $_LW->page
, which I could try to work around kind of like this:
- Check page for
/details/profiles
to know it’s a profile. - Check page for not having
/details/
to know it’s (most likely) a page.
But that doesn’t feel certain enough. I’m hoping there’s something more direct like if (type == 'page')
available to use.
Thanks,
Nick