Is There A Way To Hide The Value Of A 'global' Variable Passed Through Event Listener, While Still Letting The Script Run?
I am creating a plugin on OctoberCMS, where the user can input a code into a field in the plugin Settings menu. I've saved this input into a global variable, which I've pasted on the template for the pages.
In Plugin.php, the code for saving it into a global variable:
public function boot()
{
Event::listen('cms.page.beforeDisplay', function($controller, $url, $page) {
$settings = Settings::instance();
$script = $settings->script;
$controller->vars['script'] = $script;
});
}
In the template.htm, calling the variable in the tags:
{{ script | raw }}
which then displays the code that was inputted, when inspecting the page.
My question is, is there a way for the actual value of the variable to be hidden but for the script to still run? So that any users who view the website won't be able to 'inspect' it and see what the script is. Thanks
Answer
If you want to do like Google Analytics script does then you need to make script file.
your-javascript-file.js
now host it anywhere on other domain or on same site and copy its url.
now in your setting $settings->script
for this variable, from back-end settings you can set value like.
<script src="https://your_site/something/your-javascript-file.js"></script>
so in your web page it will show something ^ like this but not actual code. user need to dig one step more to see actual code. but yes in your web-page's source code only this single line will appear not js code it self.
if any doubts please comment.
Related Questions
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?