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
The Public Knowledge Project Support Forum is moving to http://forum.pkp.sfu.ca

This forum will be maintained permanently as an archived historical resource, but all new questions should be added to the new forum. Questions will no longer be monitored on this old forum after March 30, 2015.

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: No registered users and 1 guest