In particular, if you want to pass data to a template file that doesn’t already exist, here’s a quick example of how you can hook in before a template is loaded from a theme plugin:
As you go about implementing your changes, I’d encourage you to especially look at the Child Theming API, which will allow you to isolate specific changes and hopefully help you maintain your customizations over time:
Thanks for your both advices on the back-end and front-end aspects. And thanks for the link to the “PKP Theming Guide GitBook” which is very useful.
You’re right @NateWr, we’ve found the theming API and now we want to use it. And we want to pass data to a template file that doesn’t already exist.
I tested it by trying to get the acceptance date of the article.
I create a public function “loadTemplateData” in the CustomThemePlugin.inc.php file.
As @ctgraham has suggested, to get the acceptance date, I used the “EditDecisionDAO” as this:
$editDecisionDao = DAORegistry::getDAO(‘EditDecisionDAO’);
And then I need to use the getEditorDecisions function which takes at least the article Id as argument.
But how I get the article Id data in the loadTemplateData function ?
I have an other question related to customization. Has the Custom Locale Plugin been adapted for OJS3 ?
Thanks again for your answers.
Best regards.
Helene
I @NateWr,
I don’t manage to receive arguments of article objects in my custom theme function.
Maybe I don’t do it the right way. I was also wondering if it was possible because the theme is called before the article page ?
Thanks, Helene
I again @NateWr,
I tried several things in the CustomThemePlugin.inc.php file:
Add in the “init” function or in the new “loadTemplateData” function this line code:
HookRegistry::call(‘ArticleHandler::view’, array(&$request, &$issue, &$article));
Add in the “init” function this line code:
HookRegistry::register(‘ArticleHandler::view’,array(&$this, ‘articleView’));
and then create an “articleView” function.
Otherwise, I manage to do it in the article_details.tpl file where I can get the article Id ($article->getId()) but I would prefer to handle the code outside a template file.
Thanks, Helene
I was out of the office for a few days. And it was apparently very helpful because I finally managed to do what I wanted to do.
And your advice also directed me to the right solution.
Here’s what I did.
I Added in the “init” function this line code:
HookRegistry::register(‘ArticleHandler::view’,array($this, ‘articleView’));
And I create the articleView function as follows:
public function articleView($hookName, $args) {
$templateMgr = TemplateManager::getManager($request);
$article =$args[2];
$editDecisionDao = DAORegistry::getDAO(‘EditDecisionDAO’);
$templateMgr->assign(‘editDecisionDao’, $editDecisionDao);
$editorDecisions = $editDecisionDao->getEditorDecisions($article->getId());
$lastDecision = count($editorDecisions) >= 1 ? $editorDecisions[count($editorDecisions) - 1] : null;
$dateAccepted = $lastDecision[‘decision’] == 1 ? $lastDecision[‘dateDecided’] : null;
$templateMgr->assign(‘dateAccepted’, $dateAccepted);
}
I had no need to use the following function in the init:
HookRegistry::register (‘TemplateManager::display’, array($this, ‘loadTemplateData’));
And I manage to get the article Id ($article->getId()) by initializing $article variable with the good argument (number 2). I think, at first I didn’t initialized the $article variable with the good argument number.
This allowed me to understand how to pass data to a template file in the theming API.
Thanks a lot for all your advices and your help.
Best regards.
Helene
Glad you were able to get it working! It’s great to see people pushing what the theme api can do.
The ArticleHandler::view hook is a special hook specifically for the article view page. But not every template has it’s own special hook. So in those cases, you may need to use the TemplateManager::display hook to get into the template before it’s rendered.
Hi, I am using OJS 3.1. Could you please tell me the steps used to create this function (Accepted Date). What codes should I add and in which files. I tried doing these steps:
The “public function articleView” must also be present in your theme’s inc.php file and not in your javascript.js file. This function is in PHP code and not in Javascript code.
And getDateAccepted is a variable and not a function that must be called like that and not with $article object.
Here is what you need to do:
Copy “HookRegistry::register” code in your theme’s inc.php file at the beginning of init function
Copy “public function articleView” in your theme’s inc.php file outside init function (for example after getDescription function)
Add for example the following code in your theme’s template file: {$dateAccepted|date_format:"%e %B %Y"}
In which template file do you display $dateAccepted variable ?
To verify if data of public function articleView is well called in your template file, can you add this code at the beginning of function articleView: echo "function articleView</br>";
I have also added dateaccepted in my article_details.tpl
I have also added “function articleView ”; as per your suggestion and it is displaying on the top
It’s a good news.
In this kind of situation you have to progress step by step to see where it doesn’t work.
Modify the code of public function articleView as follows:
Hi @varshilmehta, finally did you get this?
I have tried everything I found in this forum (#3061, the plugin from Github and several ways to get the acceptance date to show up in article_details template) but I can not make it to work.
We are using a custom bootstrap 3 theme on a OJS 3.1 and so far I worked on BootstrapThreeThemePlugin.inc.php to load the articleView function, and the HookRegistry in the init fuction. Also I have tried several ways to call the variable $dateAccepted from the smarty template, but always get blank result.
As @hcl proposed, I modified the code of public function as follows:
And I get this at the top:
It looks like the variable $dateAccepted is not saving any value…
This is how I am trying to get the date in the smarty template “article-details.tpl”.
We use Bootstrap and have completely changed the frontend of the publishing process. Attached are some screenshots.
At the same time we have implemented many other options such as generating PDF certificates of reviews automatically from the reviewer panel or sending propossals to Ithenticate “on demand” (not automatically) retrieving the report from OJS.