[OJS 3.1] Adding template variable

Hello all,

I would like to add a checkbox option to the Theme to dis/enable PKP Logo at the footer, as OJS may be used for other purposes than journal publishing and showing that logo may not be interesting in the footer.

I’ve read the Theming guide and managed to add a radio option, but that’s not ideal, as a checkbox would be more effective, but I can’t figure out how to do this…

I’ve managed to add the variable to the $templateMgr environment and manually set it with a public function loadTemplateData($hookName, $args).

However, I can’t create an option for the template.
This is what I have so far… any ideas?
public function init() {

HookRegistry::register (‘TemplateManager::display’, array($this, ‘loadTemplateData’));

$this->addOption(‘pkpLogoFooter’,'checkbox’,array(
‘label’ => ‘plugins.themes.ibict2020.option.pkpLogoFooter.label’,
‘description’ => ‘plugins.themes.ibict2020.option.pkpLogoFooter.description’,
’options’=>array(0 => “plugins.themes.ibict2020.pkpLogoFooter.enable”)
));
Only ‘radio’ works and requires multiple options. Checkbox doesn’t show anything, not even label and description.

Hi there,

as far as I know in OJS 3.1 there is not way to add a checkbox. But this has changed in 3.2. I had the same trouble with my own child themes. I’ve used radio buttons for the 3.1 Version and am currently changing them to checkboxes in preparation of our upgrade to 3.2.

If you don’t want or can’t upgrade, you can also hide the Logo with CSS. Every journal can have its own stylesheet.

Hello all,

For anyone willing to add an option in their themes to hide/show PKP Logo on footer, here’s what I did:

1 - in themeName.inc.php

  public function loadTemplateData($hookName, $args) {

	// Retrieve the TemplateManager
	$templateMgr = $args[0];

	// set/get footer option to remove PKP Logo from footer
    if ($this->getOption('pkpLogoFooter') ) {
        $pkpLogoFooter = $this->getOption('pkpLogoFooter');
    }else{
        $pkpLogoFooter = 'enable';
    }
    
    // assign $pkpLogoFooter variable to $templateMgr
    $templateMgr->assign('pkpLogoFooter', $pkpLogoFooter);
}

2 - Within the public init() function of the theme, create the option selector
public function init() {

   HookRegistry::register ('TemplateManager::display', array($this, 'loadTemplateData'));
    
    // create pkpLogoFooter option
    $this->addOption('pkpLogoFooter','radio',array(
        'label' => 'plugins.themes.ibict2020.option.pkpLogoFooter.label',
        'description' => 'plugins.themes.ibict2020.option.pkpLogoFooter.description',
        'options'=>array(
            'enable' => "plugins.themes.ibict2020.pkpLogoFooter.enable",
            'disable' => "plugins.themes.ibict2020.pkpLogoFooter.disable",
            )
        ));

3 - In themeName/templates/frontend/components/footer.tpl

    {* check if $pkpLogoFooter should be displayed *}
    {if $pkpLogoFooter == 'enable'}
	<div class="pkp_brand_footer" role="complementary">
		<a href="{url page="about" op="aboutThisPublishingSystem"}">
			<img alt="{translate key="about.aboutThisPublishingSystem"}" src="{$baseUrl}/{$brandImage}">
		</a>
	</div>
    {/if}

Hello all,

[UPDATED 2020-07-22 @ 17h29 -3GMT]
I somehow solved this, adding a bit more controls, setting the empty variable first and if no value is set, if the theme option doesn’t exist, set to enable…
Now it works…
Leaving the history for anyone else…

Unfortunately, this doesn’t work on site level…
Any ideas?
I enabled debugging and stacktrace, but log doesn’t seem very helpful.

Deprecated : Methods with the same name as their class will not be constructors in a future version of PHP; ADODB_Cache_File has a deprecated constructor in C:\Meus-Documentos\laragon\www\revista.ibict.br\lib\pkp\lib\adodb\adodb.inc.php on line 263

Deprecated : Methods with the same name as their class will not be constructors in a future version of PHP; ADOConnection has a deprecated constructor in C:\Meus-Documentos\laragon\www\revista.ibict.br\lib\pkp\lib\adodb\adodb.inc.php on line 359

Deprecated : Methods with the same name as their class will not be constructors in a future version of PHP; ADORecordSet has a deprecated constructor in C:\Meus-Documentos\laragon\www\revista.ibict.br\lib\pkp\lib\adodb\adodb.inc.php on line 2921

Deprecated : Methods with the same name as their class will not be constructors in a future version of PHP; ADORecordSet_array has a deprecated constructor in C:\Meus-Documentos\laragon\www\revista.ibict.br\lib\pkp\lib\adodb\adodb.inc.php on line 3939

Deprecated : The each() function is deprecated. This message will be suppressed on further calls in C:\Meus-Documentos\laragon\www\revista.ibict.br\lib\pkp\lib\adodb\adodb.inc.php on line 1003

Warning : count(): Parameter must be an array or an object that implements Countable in C:\Meus-Documentos\laragon\www\revista.ibict.br\cache\t_compile\65bfc3e024c2e9104f46e23b73376a9455e3df0e^51cfb9321c891ada9323e7942962579e7e4324d1_0.app.frontendpagesindexSite.tp.php on line 43

At the footer, this seems the culprit, but I have no idea how to solve this for the website level:

Fatal error : Uncaught Error: Call to a member function getOption() on null in C:\Meus-Documentos\laragon\www\revista.ibict.br\cache\t_compile\65bfc3e024c2e9104f46e23b73376a9455e3df0e^4dffb64063bb972c37e05619a2ccd9d0ea7473ac_0.app.frontendcomponentsfooter…php:91 Stack trace: #0 C:\Meus-Documentos\laragon\www\revista.ibict.br\lib\pkp\lib\vendor\smarty\smarty\libs\sysplugins\smarty_template_resource_base.php(123): content_5f185e3a949707_16420731(Object(Smarty_Internal_Template)) #1 C:\Meus-Documentos\laragon\www\revista.ibict.br\lib\pkp\lib\vendor\smarty\smarty\libs\sysplugins\smarty_template_compiled.php(114): Smarty_Template_Resource_Base->getRenderedTemplateCode(Object(Smarty_Internal_Template)) #2 C:\Meus-Documentos\laragon\www\revista.ibict.br\lib\pkp\lib\vendor\smarty\smarty\libs\sysplugins\smarty_internal_template.php(216): Smarty_Template_Compiled->render(Object(Smarty_Internal_Template)) #3 C:\Meus-Documentos\laragon\www\revista.ibict.br\lib\pkp\lib\vendor\smarty\smarty\libs\sysplugins\smarty_internal_template.php( in C:\Meus-Documentos\laragon\www\revista.ibict.br\cache\t_compile\65bfc3e024c2e9104f46e23b73376a9455e3df0e^4dffb64063bb972c37e05619a2ccd9d0ea7473ac_0.app.frontendcomponentsfooter…php on line 91

What is the content of line 91 in the compiled template? I was expecting to see a fatal error referencing an unset $context, but it seems to reference the getOption() method from your plugin instead. But, your changes to themeName/templates/frontend/components/footer.tpl don’t seem to reference your plugin’s getOption() method directly.

Hello @ctgraham,

I couldn’t manage to get the template variables into the footer, so I added a function in the theme function to set the variable in templateMgr… It’s working now somehow…

I faced some issue after upgrade from 3.1 to 3.2 and it fixed by using retry to set the theme again from
Hosted Journals > Setting Wizard > Appearance > Theme must be set and save after upgrade.