[SOLVED][OJS 3.1.0-1] Use array variable in mail templates

Hi everyone,

Does anyone have a tip on how to display the submission checklist items in the submission acknowledgement mail? We’d like to record the authors agreement to the checklist within OJS. (See original issue on GitHub for rationale.)

I’m currently stuck on iterating through the array of checklistitems in the mail template.
I got the checklist from the database table journal_settings and assigned it to the mail variables in classes/submission/form/SubmissionSubmitStep4Form.inc.php by adding this to $mail->assignParams:

‘ubma_submissionChecklist’ => $context->getSetting(‘submissionChecklist’),

Evaluating that in the mailtemplate with {$ubma_submissionChecklist} gives me (as expected) the output Array. However I don’t get the expected results when trying to iterate through this in the mail template:

During submission you agreed to the following points:
<ul>
foreach ($ubma_submissionChecklist as $item) {
echo "<li>$item</li>");
}
</ul>

Playing around with curly brackets around the loop didn’t help so far. Is it even possible to use a loop in a mail template? If so, how would I do this correctly? And if not: Can I iterate through the array before assigning the parameters to the mail template?

Any help is much appreciated!

Kind regards
Dennis

Hi @dennmuel

That setting is localized, i.e. you would need to get it in the locale you wish, probably in the current UI locale: $context->getLocalizedSetting('submissionChecklist'); – The way you get it returns the array with all existing locales of the setting.
Then, the setting itself is also an array of arrays.
Thus, you would need to create a HTML string first, that you would then assign as an e-mail parameter.
Something like:

$emailCheckList = '';
$checklist = $context->getLocalizedSetting('submissionChecklist');
if (!empty($checklist)) {
ksort($checklist);
reset($checklist);
$emailCheckList .= __('about.submissionPreparationChecklist');
$emailCheckList .= '<ul>'
foreach ($checklist as $item) {
$emailCheckList .= '<li>'.nl2br($item['content']).'</li>';
}
$emailCheckList .= '</ul>';
}

And then you would assign $emailCheckList as the email parameter:
‘ubma_submissionChecklist’ => $emailCheckList

Eventually you would not need this line above:
$emailCheckList .= __('about.submissionPreparationChecklist');
or even <ul> and </ul>
if those are parts of your e-mail template text.

Let me know if there are any further problems/questions…

Best,
Bozana

1 Like

Hi @bozana,

thank you so very much! That worked like a charm, absolutely fantastic. :tada:
Didn’t think about the localization structure at all, so that was an extra lesson learned… Combined with your tips from the ticket we got it now working as we hoped. Thanks a lot! :slight_smile:

Kind regards
Dennis

Glad it worked! :ok_hand: :clap: :raised_hands: :tada: :smile:

Hi @bozana (and others, too) :slight_smile:

Sorry to bring this up again, but I was hoping you could help me once more…

Still the goal is to assign a parameter ubma_submissionChecklist (holding the submission checklist the author confirmed during the submission process) to the SUBMISSION_ACK mail template.

Back then I’ve used your instructions above to add 'ubma_submissionChecklist' => $myChecklistString directly to this array. This still works nicely, but now I’d like to move this customization to a generic plugin instead of directly editing that file.

However, I’m struggling to find out how to actually get there. Simply placing an edited file in templates/classes/submission/form/SubmissionSubmitStep4Form.inc.php in the plugin dir does not seem to do the trick - the mail displays the variable name instead of the actual string.

What hook(s) must I use to hook into the submission, get the checklist string and assign it to the email template? Does the plugin need to have any special qualities, e.g. like HookRegistry::register('TemplateResource::getFilename', array($this, '_overridePluginTemplates'));?

I couldn’t really get the pieces together from reading the documentation about email templates and couldn’t find a list of hooks to go through and try either.

Any help is much appreciated!

Best regards
Dennis