You are viewing the PKP Support Forum | PKP Home Wiki

Show Current Issue in Block

OJS development discussion, enhancement requests, third-party patches and plug-ins.

Moderators: jmacgreg, btbell, michael, bdgregg, barbarah, asmecher

Forum rules
Developer Resources:

Documentation: The OJS Technical Reference and the OJS API Reference are both available from the OJS Documentation page.

Git: You can access our public Git Repository here. Comprehensive Git usage instructions are available on the wiki.

Bugzilla: You can access our Bugzilla report tracker here.

Search: You can use our Google Custom Search to search across our main website, the support forum, and Bugzilla.

Questions and discussion are welcome, but if you have a workflow or usability question you should probably post to the OJS Editorial Support and Discussion subforum; if you have a technical support question, try the OJS Technical Support subforum.

Show Current Issue in Block

Postby mmott » Fri Dec 20, 2013 9:36 am

Hi, I'm attempting to write a block plugin to show the cover of the current issue in a block in the sidebar. I followed the write your own block guide and have everything ready apart from the template. I need to somehow invoke the current issue before I can get to the $coverPagePath, $currentUrl et cetera. I've done a fair amount of WordPress development and usually you make a custom loop, much like
Code: Select all
{iterate from=issues item=issue}
in the archive.tpl but only get the recent one. Does OJS work anything like this? And if so how can i invoke the current issue? Below is the code of my block.tpl file.

Code: Select all
<div class="block" id="sidebarCurrentIssue">
   {if $coverPagePath}<div id="sidebarIssueCoverImage"><a href="{$currentUrl}"><img src="{$coverPagePath|escape}{$issue->getFileName($locale)|escape}"{if $coverPageAltText != ''} alt="{$coverPageAltText|escape}"{else} alt="{translate key="issue.coverPage.altText"}"{/if}{if $width} width="{$width|escape}"{/if}{if $height} height="{$height|escape}"{/if}/></a></div>{/if}

I can put something like
Code: Select all
in front of it, but that seems to affect whatever comes after the sidebar. I just need to access the current issue once and subsequently let the page return to its normal routine.

Any help would be appreciated.

Thanks, Maarten
Posts: 2
Joined: Tue Dec 17, 2013 8:03 am

Re: Show Current Issue in Block

Postby asmecher » Fri Dec 20, 2013 11:16 am

Hi Maarten,

A couple of common pitfalls:
  • Expose the content you want in the plugin class using the template manager. In this case you can get the object from the IssueDAO using the getCurrentIssue function. Something like...
    Code: Select all
    $templateMgr = TemplateManager::getManager();
    $journal =& Request::getJournal();
    $issueDao =& DAORegistry::getDAO('IssueDAO');
    $currentIssue =& $issueDao->getCurrentIssue($journal->getId());
    $templateMgr->assign('currentIssueBlockIssue', $currentIssue);
  • Watch out that you don't clobber existing variable names in the template. Template variables are global, so just calling it "issue" runs the risk of running into another part of the code using the same variable name.
Alec Smecher
Public Knowledge Project Team
Posts: 10015
Joined: Wed Aug 10, 2005 12:56 pm

Return to OJS Development

Who is online

Users browsing this forum: Google [Bot] and 2 guests