Where can I learn about passing a php value from 'SMF' to 'index.template.php'?

Started by richardwbb, March 08, 2018, 09:53:28 AM

Previous topic - Next topic

richardwbb

I'm aware of;
ManageSettings.php
Load.php
Modifications.english.php

I would be able to create a master switch that will end up in 'Modification Settings - Miscellanous', using two languages and maybe make use Load.php to load a .js file. For the latter I'm not sure yet, since my modification won't work without a unique div element for it, but my question is;

The only way to turn on or off my modification -without- flickering, is by using echo '<div id="', $modification-variable ,'"></div>', where this would be a simple 'on' or 'off', no integers, but literal text. Could someone please explain with a few words or where do I have to look or read a manual to learn how to pass a variable to an php echo inside a index.template.php?
If my post in this topic looks ambiguous to you, then I'm with Murphy's law and General Stupidity. In other words, trial and error.

richardwbb

I've gotten a little further with my modification, now I wonder if the following code that is working<file name="$sourcedir/Load.php">
<operation>
<search position="after"><![CDATA[ // We are ready to go.]]></search>
<add><![CDATA[
$context['html_headers'] .= '<script type="text/javascript" src="'. $settings['default_theme_url']. '/scripts/modification.js"></script>';

]]></add>
</operation>
</file>
is a proper way of making sure a javascript file will be loaded?
If my post in this topic looks ambiguous to you, then I'm with Murphy's law and General Stupidity. In other words, trial and error.

Suki

Any variable created with ManageSettings.php will be loaded by SMF under the global array $modSettings, usually you define a unique key for your setting:


$config_vars[] = array('check', 'my_mod_master', 'subtext' => 'some text');


Your setting will be available in the "my_mod_master":   $modSettings['my_mod_master'], you can use that variable inside any template as most of them already globalize $modSettings.

Just be careful, use empty on your key before using it:

if (!empty($modSettings['my_mod_master']))
    // some logic with $modSettings['my_mod_master'] here

Since you don't always know if the admin has activated that checkbox or put some text on that text field, etc.
Disclaimer: unless otherwise stated, all my posts are personal and does not represent any views or opinions held by Simple Machines.

Advertisement: