OJS 3.1 How to send publishedArticles variable to the article detail page

Hi everyone.

I am customizing a OJS 3.1 journal. My goals are to add some custom content to the sidebar depending of the current view. I have read the PKP Theming Guide, so I am using a (Child Theme) for accomplish my goal.

One of my objective is to show the rest of issue’s articles for my current article and some related articles with my current article in its article detail view as show in the following image.

I have studied the code of some templates in ojs/templates/frontend as issue_toc.tpl and I found that this template use the publishedArticles variable, so I am looking the way to send these variable to my footer.tpl (I found in this template there is the sidebar code) that’s why I write this topic to ask to PKP team if someone knows how to achieve this problem or if someone suggest other way to resolve my problem.

You could create a custom block plugin. See for example the Language switcher: https://github.com/pkp/ojs/tree/master/plugins/blocks/languageToggle

How the get the current article, see https://github.com/pkp/ojs/blob/master/plugins/generic/recommendBySimilarity/RecommendBySimilarityPlugin.inc.php#L72
And also see that whole generic plugin, which is related to your plans.

Thanks a lot for your reponse @ajnyga it’s an alternative to the way I was following and it seems very interesting because this way I will add the functionality for accomplish my goals through your way, without modify the core code of OJS which I am worry because if I modify the core code of OJS could bright me troubles to the time of upgrading.

With respect to the plugin recommendBySimilarity, I didn’t know about it. I have to learn more about OJS’s plugins. One more time thanks a lot for share your knowledge.

1 Like

Hi @asmecher

I apologize for tag you in this topic, but it seems you are an active user in this forum. Following the response of @ajnyga for my problem, I would like to konw where can I get some information about the development of a plugin?

In specific I would like to know about how can I get the data from pages, for example in the article detail page I would like to get the information about article’s issue and with this data to get the list of publishedArticles for this issue.

My first attempt was to implement a new child-theme (I have read the complete https://pkp.gitbooks.io/pkp-theming-guide/content/en/) and in my DefaultChildThemePlugin class I retrieve the published articles for the current issue, but I want the published articles for the issue to which the article I am seeing belongs.

I have seen in the RecommendBySimilarityPlugin class the use of

$displayedArticle = $smarty->get_template_vars('article');

But I have the doubt if this get_template_vars method is available for all the pages of OJS?

I hope you can help me, in advance thank you very much.

Hi @juancure,

The get_template_vars function is part of the Smarty library. The TemplateManager class in our software is a subclass of the Smarty class, so you can call Smarty’s functions there. You can always get the template manager by calling:

$templateMgr = TemplateManager::getManager($request);

The get_template_vars function can be used to get any variable that was already assigned to the template manager using $templateMgr->assign. (This, again, is a Smarty function.)

Regards,
Alec Smecher
Public Knowledge Project Team

Hi @asmecher, thanks a lot for answer mi specific question.

I have accomplished my first goal. Below I left the code of my function loadTemplateData() in my ChildThemePlugin class:

public function loadTemplateData($hookName, $args) {

    // Retrieve the TemplateManager
    $templateMgr = $args[0];
    $template = $args[1];

    // Don't do anything if we're not loading the right template
    if ($template != 'frontend/pages/article.tpl') {
        return;
    }

    // getting the issue associated to the templateMgr
    $displayedIssue = $templateMgr->get_template_vars('issue');

	$publishedArticleDao = DAORegistry::getDAO('PublishedArticleDAO');
	$publishedArticles = $publishedArticleDao->getPublishedArticlesInSections($displayedIssue->getId(), true);

    // Attach a custom piece of data to the TemplateManager
    $myCustomData = 'This is my custom data. It could be any PHP variable.';
    $templateMgr->assign(array(
    	'myCustomData' => $myCustomData,
    	'myPublishedArticles' => $publishedArticles
    	));
}

With my code above and using a Child Theme, I got a list of the rest of articles contained in the same issue in the sidebar for the article detail page as show in the below image.

My other goal is to get a list of recommended articles in the side bar for the article detail page, below of the Most articles by the same issue section. Thanks to @ajnyga I am using the RecommendedByAuthor plugin. However this plugin render the information above of footer, I would like to change this information to the sidebar.

I have reviewed in the code of the plugin and I have noticed that the plugin register the hook ‘Templates::Article::Footer::PageFooter’ to indicate where position the info. I have found this hook is in the template templates/frontend/pages/article.tpl and I moved this hook to my child theme’s template templates/frontend/components/footer.tpl, but this step crash the loading of some scripts that load in my init() function in my ChildThemePlugin class.

How can change the position of the resulting article list for RecommendedByAuthor plugin to the sidebar?