Iterate Issue in indexJournal.tpl file

Dear all…
Please help me to run iterate in the indexJournal.tpl file.

I write like this:
{iterate from=issues item=issue}
{include file=“frontend/objects/issue_frontpage.tpl” heading=“h3”}
{/iterate}

But not showing anything…

Greetings @medankia

As I know in Smarty you can iterate through foreach, where have you found iterate operator?

Also, what you want to accomplish with this code? Can you include more info about the problem (PKP application (OJS?), version etc.)?

Hi @Vitaliy

Thanks for your response…
I Use OJS Version 3.x

In the issueArchive.tpl file there is a command line to display issue list like this:


    {iterate from=issues item=issue}

  • {include file=“frontend/objects/issue_summary.tpl”}

  • {/iterate}

I put the command line into the indexJournal.tpl file, but no data appears.
What’s the solution?

I have just checked. Calling getPageCount() function on $issues gives an error:
PHP Fatal error: Uncaught Error: Call to a member function getPageCount() on null

Think $issues is not defined when using outside of that page. You can try to call issues from a plugin (so you would need to make one).

Just tried to call issue object (from PHP). Seem to work:

$issuesDAO = DAORegistry::getDAO('IssueDAO');
print_r($issuesDAO);

Also I am not a developer.

Hi @Vitaliy

You’re right, $issues is not defined in the indexJournal.tpl file. To fix this, I copied some lines from the IssueHandler.inc.php file into the IndexHandler.inc.php file. It works! I’m not sure that’s the right way, I’m not proud of that :blush:

My problem now, how to limit the data processed by that command {iterate} {/iterate}? How to limit the data so it does not appear entirely? Please help me…

Keep in mind that all changes in OJS core files will be lost after next update (unless you use diff or sonething similar.
What you want to limit? Number of issues displayed?

Thanks @Vitaliy

Yes, how to limit number of issues displayed In command {iterate} {/iterate}?

It is better to limit it on the PHP side. Also I couldn’t find iterate operator in the Smarty documentation.

If in template, you can try something like:

{foreach from=$issues key=k item=issue}
    {if $k<10}
        {include file="frontend/objects/issue_summary.tpl"}
    {/if}
{/foreach}

where k is you number, what you want to display (from 0)

I hope $issues is an array, where key is just a default number. But this could not be the case. Didn’t check it.

Hi all,

The {iterate} function is a PKP extension to Smarty, and can be used to walk through the results of functions that return ItemIterator classes. The {foreach} function is a Smarty builtin that works on arrays. FYI, you can convert ItemIterator classes to arrays by calling the toArray function on the PHP side.

Note that ItemIterators can typically only be iterated once.

Regards,
Alec Smecher
Public Knowledge Project Team

Hi @Vitaliy and @asmecher
What you have described is valuable and important information to my question that will guide me find the command and put it in the right place.

Thanks for taking the time to answer my question.

Hello,

I have the same issue like you, I am not sure which code I need to add to my handler, is it possible to tell me or explain to me that

Dear,
I am trying to do almost samething, iterating all the issues in indexjournal
.tpl so I added this code to indexhandler but still not working

$issues = $issueDao->getCurrent($journal->getId(), true);
if (isset($issues) && $journal->getSetting(‘publishingMode’) != PUBLISHING_MODE_NONE) {
import(‘pages.issue.IssueHandler’);// The current issue TOC/cover page should be displayed below the custom home page.
IssueHandler::_setupIssueTemplate($request, $issues);
}

From the otherside of indexjournal.tpl i did add the code:

{foreach from=$issues item=issue}
    {include file="frontend/objects/issue_summary.tpl"}

{/foreach}

$issues always null which doesn’t let the iterating appears , any solution?

Can you show the whole code you have in your theme plugin?

$issues = $issueDao->getCurrent($journal->getId(), true);

Will only return one issue, the latest one. The functions needed are explained here Display all the issues on the home page instead of current issue - #2 by ajnyga.

exactly, ti returns only the current issue, I did follow the documentation however, I am not sure if what I am doing is write since there is no result.

It should be something easy to implement since the code is the same like archive menu, the only difference is to pass it through the indexjournal.tpl

here is the code of theme plugin:
if (!$journal) {
$journal = $this->getTargetContext($request, $journalsCount);
if ($journal) {
// There’s a target context but no journal in the current request. Redirect.
$request->redirect($journal->getPath());
}
if ($journalsCount === 0 && Validation::isSiteAdmin()) {
// No contexts created, and this is the admin.
$request->redirect(null, ‘admin’, ‘contexts’);
}
}

	$this->setupTemplate($request);
	$router = $request->getRouter();
	$templateMgr = TemplateManager::getManager($request);
	if ($journal) {
		// Assign header and content for home page
		$templateMgr->assign('additionalHomeContent', $journal->getLocalizedSetting('additionalHomeContent'));
		$templateMgr->assign('homepageImage', $journal->getLocalizedSetting('homepageImage'));
		$templateMgr->assign('homepageImageAltText', $journal->getLocalizedSetting('homepageImageAltText'));
		$templateMgr->assign('journalDescription', $journal->getLocalizedSetting('description'));

		$issueDao = DAORegistry::getDAO('IssueDAO');
		$issue = $issueDao->getCurrent($journal->getId(), true);
		if (isset($issue) && $journal->getSetting('publishingMode') != PUBLISHING_MODE_NONE) {
			import('pages.issue.IssueHandler');
			// The current issue TOC/cover page should be displayed below the custom home page.
			IssueHandler::_setupIssueTemplate($request, $issue);
		}
		
		
		$issues = $issueDao->getCurrent($journal->getId(), true);
		if (isset($issues) && $journal->getSetting('publishingMode') != PUBLISHING_MODE_NONE) {
			import('pages.issue.IssueHandler');// The current issue TOC/cover page should be displayed below the custom home page.
			IssueHandler::_setupIssueTemplate($request, $issues);
		}
		

	
	
	
	

		$enableAnnouncements = $journal->getSetting('enableAnnouncements');
		if ($enableAnnouncements) {
			$enableAnnouncementsHomepage = $journal->getSetting('enableAnnouncementsHomepage');
			if ($enableAnnouncementsHomepage) {
				$numAnnouncementsHomepage = $journal->getSetting('numAnnouncementsHomepage');
				$announcementDao = DAORegistry::getDAO('AnnouncementDAO');
				$announcements =& $announcementDao->getNumAnnouncementsNotExpiredByAssocId(ASSOC_TYPE_JOURNAL, $journal->getId(), $numAnnouncementsHomepage);
				$templateMgr->assign('announcements', $announcements->toArray());
				$templateMgr->assign('enableAnnouncementsHomepage', $enableAnnouncementsHomepage);
				$templateMgr->assign('numAnnouncementsHomepage', $numAnnouncementsHomepage);
			}
		}

		$templateMgr->display('frontend/pages/indexJournal.tpl');
		
		
		
	} else {

Is this from a theme plugin or are you trying to modify the OJS core? Because this looks like the contents of IndexHandler.inc.php.

Modifying the core is of course an option, but you will loose those changes during each upgrade.

Actually it is the core indexhandler.ini.php

I could not find theme plugin since I am using bootstrap theme, of course if you orient me to develop the theme plugin will be better, since I would like to keep updating my OJS 3

The theming guide I linked in the other thread shows how to create child themes.

You could basically create a child theme of the bootstrap theme and only add the modifications you need to your child theme (in this case the modified template file and the custom data to be passed to that template).

So I suggest that you start by reading the guide, at least about child themes and then about passing custom data to templates. There is a whole section titled “Child Theming the Bootstrap3 Theme” and “Passing Data to a Single Template”.

I am sure that you could achieve this also by editing the core and of course you could apply your changes after each upgrade.

I want to do samething. Have you achieved it?

1 Like