Created
February 5, 2013 20:43
-
-
Save sorbing/4717479 to your computer and use it in GitHub Desktop.
How to detect what specified `require()` has been executed?
Discussion: https://groups.google.com/d/topic/requirejs/vM3pCCOtQYE/discussion
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!-- Template: layout.php --> | |
| <!-- include require.js and maim.js --> | |
| ... | |
| <?php include "first.php" ?> | |
| <?php | |
| if ($_GET['condition']) { // some condition | |
| include "second.php"; | |
| } else { | |
| include "third.php"; | |
| } | |
| ?> | |
| <!-- Template: first.php --> | |
| <script type="text/javascript"> | |
| requirejs(['one', 'two'], function (one, two) { | |
| // !! How to execute some code only once, when executed `one.someSetup` in second.php template? | |
| // !! I can not use a nested `require()` this.. | |
| }); | |
| </script> | |
| <!-- Template: second.php --> | |
| <script type="text/javascript"> | |
| requirejs(['one'], function (one) { | |
| one.someSetup({ | |
| option1: <?php echo $someServerVariable ?>, | |
| option2: 'someStatisValue' | |
| }); | |
| }); | |
| </script> | |
| <!-- Template: third.php --> | |
| <script type="text/javascript"> | |
| requirejs(['one'], function (one) { | |
| one.someSetup({ | |
| option1: <?php echo $otherValue ?>, | |
| option2: null | |
| }); | |
| }); | |
| </script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment