You are viewing the PKP Support Forum | PKP Home Wiki

Developing a block plugin, how to define where to be display

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.

Developing a block plugin, how to define where to be display

Postby juli » Thu Aug 02, 2012 1:25 am

Hi all!

I'm working in a announcement block to display the last 3 announcemnts in the sidebar with a block. I have it working but it's only displayed in the admin sections, like configuration.

The code is based on the 'developed by' plugin adding the getContents to pass the announcemnts data to block.tpl.

Anyone can help me? any indication will be welcome!

thanks a lot!

Code: Select all


class AnnouncementsBlockPlugin extends BlockPlugin {

  function getEnabled() {
    if (!Config::getVar('general', 'installed')) return true;
    return parent::getEnabled();

  function getInstallSitePluginSettingsFile() {
    return $this->getPluginPath() . '/settings.xml';

  function getContextSpecificPluginSettingsFile() {
    return $this->getPluginPath() . '/settings.xml';

  function getBlockContext() {
    if (!Config::getVar('general', 'installed')) return BLOCK_CONTEXT_RIGHT_SIDEBAR;
    return parent::getBlockContext();

  function getSeq() {
    if (!Config::getVar('general', 'installed')) return 1;
    return parent::getSeq();

  function getDisplayName() {
    return __('plugins.block.Announcements.displayName');

  function getDescription() {
    return __('plugins.block.Announcements.description');

  function getContents(&$templateMgr) {
    $journal =& Request::getJournal();

    $limitRecentItems = true;
    $recentItems = 3;

    $announcementDao =& DAORegistry::getDAO('AnnouncementDAO');
    $journalId = $journal->getId();
    if ($limitRecentItems && $recentItems > 0) {
      $rangeInfo = new DBResultRange($recentItems, 1);
      $announcements =& $announcementDao->getAnnouncementsNotExpiredByAssocId(ASSOC_TYPE_JOURNAL, $journalId, $rangeInfo);
    } else {
      $announcements =& $announcementDao->getAnnouncementsNotExpiredByAssocId(ASSOC_TYPE_JOURNAL, $journalId);

    $lastDateUpdated = '';
    if ($announcements->wasEmpty()) {
      if (empty($lastDateUpdated)) {
        $dateUpdated = Core::getCurrentDate();
        $announcementBlockPlugin->updateSetting($journal->getId(), 'dateUpdated', $dateUpdated, 'string');
      } else {
        $dateUpdated = $lastDateUpdated;

    $templateMgr =& TemplateManager::getManager();
    $templateMgr->assign_by_ref('announcements', $announcements->toArray());
    $templateMgr->assign_by_ref('journal', $journal);

    return parent::getContents($templateMgr);

Code: Select all
  <setting type="bool">
  <setting type="int">
  <setting type="int">
    <value>2</value><!-- BLOCK_CONTEXT_RIGHT_SIDEBAR -->

Code: Select all
<div class="block" id="sidebarAnnouncements">
  <h2 class="blockTitle" id="announcements">{translate key="plugins.block.Announcements.blockTitle"}</h2>
    {foreach from=$announcements item=announcement}
      <li class="announcementElement"><a href="{url page="announcement" op="view" path=$announcement->getId()}" cass="announcementTitle">
        {if $announcement->getLocalizedDescription()}
          <!--div class="announcementDescription">{$announcement->getLocalizedDescription()|strip|escape:"html"}</div-->

Posts: 13
Joined: Mon Jul 16, 2012 1:18 am

Re: Developing a block plugin, how to define where to be dis

Postby juli » Fri Aug 03, 2012 1:26 am

Hi all!

a good documentation is always the solution! I found this wiki link: http://pkp.sfu.ca/wiki/index.php/Writing_a_Block_Plugin and executing the last pas I solved my problem!

the solution:
Code: Select all
php tools/upgrade.php upgrade
Posts: 13
Joined: Mon Jul 16, 2012 1:18 am

Re: Developing a block plugin, how to define where to be dis

Postby anfemora » Tue Sep 17, 2013 3:32 pm

Hi juli!
Could you please explain more precisely how you did it?
I would like to show a custom, very simple block on a sidebar, but only in the static pages, not in the rest.
How could that be done? I cannot write php, so some code indications would be very useful to me.
Thank you!
Posts: 2
Joined: Thu Mar 14, 2013 9:42 am

Return to OJS Development

Who is online

Users browsing this forum: No registered users and 1 guest