2

I'm very new to Moodle dev. I have read the basics of the API, and now started getting my hands dirty by making tinymce plugin. While doing so, I have encountered the following problem: How do I access settings.php from javascript.

I know how to access lan/en strings from javascript, I also know that in php, $layout_string = $this->get_config('statlayout');, will exract the setting 'statlayout'. What I want is to access $layout_string from JavaScript.

2 Answers 2

2

Well I supposed there is no standard way of doing this.

  • If you are making a plugin (not a subplugin for atto or tinymce), then you can simply call

    global $PAGE; $PAGE->requires->yui_module( /* frankenstyle named yui module /, / entry function */ );

  • If you are making a subplugin, then you need to read the main plugin itself to discover how it calls javascript functions, for atto editor's case I think I saw the following in one of the main plugin:

    reqiure_once("plugins/$pluginname/lib.php"); $functionname = "atto_".$puginname."params_for_js"; call_user_func($functionname, /* some args */ );

In which case your atto subplugin's lib.php must contain a atto_pluginname_params_for_js function, such that pluginname is the name of your plugin.

In software engineering perspective, that is beyond disgusting. All I can say to makes things better is to abide to the software engineering principles yourself when creating your own plugin and reduce intellectual baggage for the next person.

Sign up to request clarification or add additional context in comments.

Comments

0

I personally think this is really hacky, and I wouldn't recommend it, but perhaps you could do something like this?

<?php
  $layout_string = $this->get_config('statlayout');
  echo "<script> var my_var = '" . $layout_string . "';</script>";
?>

<script> alert( my_var );</script>

If you've found another answer in the meantime, I'd be interested to know what you've come up with. :)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.