¡Hola, amigos! I’m Señor FAQ, the mustached maestro of questions and answers! With my trusty glasses and a book of endless wisdom, I turn dudas into solutions. Soy el héroe de los curiosos and the champion of clarity.
on_template_load
The on_template_load
hook is executed during the template loading process in JScms.
It is particularly useful for plugins or custom logic that need to interact with page data, perform specific actions, or manipulate the rendering process based on the current page or user context.
$hookResults = DynamicHooks::executeHook(
'on_template_load',
false,
$jakdb, $jkv, $lang, $userGroupId, $page, $page1, $pageId, $jscmsLanguage
);
foreach ($hookResults as $namespace => $result) {
if (is_callable($result)) {
$result($jakdb, $jkv, $lang, $userGroupId, $page, $page1, $pageId, $jscmsLanguage);
}
}
This hook is executed using DynamicHooks::executeHook()
with the following parameters passed to the registered callbacks:
$jakdb
- The database instance.$jkv
- The configuration array.$lang
- The active language for JScms.$userGroupId
- The ID of the current user's group.$page
- The current page slug.$page1
- Additional page parameter (e.g., subpage or article ID).$pageId
- The ID of the current page.$jscmsLanguage
- The language context for JScms.
The on_template_load
hook is ideal for scenarios where plugin-specific logic or dynamic actions
need to be applied during the template loading phase. It supports tasks like dynamic page routing, content injection,
or serving custom endpoints like RSS feeds.
DynamicHooks::addHook('on_template_load', function ($jakdb, $jkv, $lang, $userGroupId, $page, $page1, $pageId, $jscmsLanguage) {
// Check if the page corresponds to the FAQ slug
if (!empty($jkv["slugforfaqarticle"]) && $page === $jkv['slugforfaqarticle'] && isset($pageId) && isset($page1)) {
// Initialize DynamicFAQ class
$faqClass = new DynamicFAQ($jakdb, $jkv, $lang, $userGroupId);
// Fetch the article data
$article = $faqClass->getFAQById($page1, $jscmsLanguage);
// Redirect if no article is found
if (!$article) {
JScms_redirect(DynamicRewrite::parseUrl($jkv["slugforfaq"]));
} else {
$articleData['title'] = $article['question'];
$articleData['seo_keywords'] = $article['seo_keywords'];
$articleData['seo_description'] = $article['seo_description'];
}
$pageToLoad = $pageId;
}
// Serve an RSS feed for a specific endpoint
if ($_SERVER['REQUEST_URI'] === '/faqrss.xml') {
$dynamicFAQ = new DynamicFAQ($jakdb, $jkv, $lang, $userGroupId);
header('Content-Type: application/rss+xml; charset=utf-8');
echo $dynamicFAQ->generateRssFeed();
exit;
}
}, 'faq');