Skip to content

Instantly share code, notes, and snippets.

@sorbing
Created February 5, 2013 20:43
Show Gist options
  • Select an option

  • Save sorbing/4717479 to your computer and use it in GitHub Desktop.

Select an option

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
<!-- 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