We build. You grow.

Get best community software here

Start a social network, a fan-site, an education project with oxwall - free opensource community software

wondering why {$year} is not a global value | Forum

dave Team
dave May 23 '13

in this text key:

 

blogs+user_blog_archive_description

 

it shows {$year}

 

this value is also represented in several other blog files.

 

but when i add {$year} to other parts of the script,

 

for example:

 

I wanted to add it to my copyright lang key so that i would not have to keep updating the year every year,  just one less thing i need to do. 

 

It does not show any value..

 

But it is obvious that the value is not global because it seems to only work for blog files or blog lang files. 

 

Im just wondering why its not global? 

And whats the best way to make it global?  

Should i set it as a superglobal in one of the classes, but which one?

 

Thanks  

 

i guess i could just define the year in the includes config file then add it to the line 216 section for globals in core application php..

 

Does that sound right?

 

The Forum post is edited by dave May 23 '13
Paul M.
Paul M. May 23 '13
Dave,


I think you would need to assign the variable as a global via smarty. http://www.smarty.net/docs/en/language.function.assign.tpl


I think it goes something like this, $smarty->assign($year);


I could be way off. I did something like awhile back with whmcs.

dave Team
dave May 23 '13

I dont think that i would need to assign it to smarty, thats the first thing i thought of but the thing is they use it now for blogs and it is not assigned to smarty.  

 

There are only three places in the whole script that this gets used..

 

ow_plugins/blogs/controllers/user_blog.php   line 29

ow_plugins/blogs/views/controllers/view_index.html  line 67

ow_plugins/blogs/views/controllers/user_blog_index.html line 29

 

 

The Forum post is edited by dave May 23 '13
dave Team
dave May 23 '13

Very strange i did get this to work but not really the way i wanted to.

 

First i defined the value in config

 

define ('show_cur_year', date('Y'));

 

Then on or about line 216 in ow_core/application.php you will see this

 

// adding global template vars

        $currentThemeImagesDir = OW::getThemeManager()->getCurrentTheme()->getStaticImagesUrl();
        $viewRenderer = OW_ViewRenderer::getInstance();

 

After that you post the new code but this is the strange part for me.

 

i first set the var this way

 

//added to set year as global
        $viewRenderer->assignVar('showyear', show_cur_year);
       

simple enough but then it would not show if i put {$showyear} in the lang file for key search copyright. 

 

shows:

 © Copyright {$showyear} mysitename

 

 

so i posted {$showyear}  directly in the theme view files  ow_themes/macrabre/master_pages  in both the index and the general html

 

and it shows fine but it sort of looks funky in this format     

 

2013© Copyright mysitename

 

I wanted it in the lang file.  

 

in which logically should work but does not in the lang key, maybe because the lang is in the db and this is not.. mmmmm

 

The Forum post is edited by dave May 23 '13
Alia Team
Alia May 27 '13
Topic was moved from General Questions.
Daisy Team
Daisy May 30 '13
Dave, we strongly recommend not to modify the core files. When you update your site - all the changes you've made will be lost.

The code you've mentioned above is quite tangled. If you want to add an additional global variable, we suggest to develop the plugin.

Here is an example of the function allowing to add a new variable as global:


 function fooo_foooooooo()
{
    $value = "Foo";
    OW_ViewRenderer::getInstance()->assignVar("someVar", $value);
}
OW::getEventManager()->bind(OW_EventManager::ON_BEFORE_DOCUMENT_RENDER, "fooo_foooooooo");
dave Team
dave May 30 '13
Thanks Daisy :)
Daisy Team
Daisy Jun 3 '13
You are welcome.
Jan Kowalski
Jan Kowalski May 9 '17
Hello!
On profile questions I have City, Country etc.
How can I add new variable like {$country} to use like:
I'm {$username} from {$country}

I'm not a programmer andI will be grateful for explanation step by step :)