Jump to content

Need to put processwire php inside a javascript string - Using Bablyon.js


gbball
 Share

Recommended Posts

<script>
//code
// Append glTF model to scene.
            BABYLON.SceneLoader.Append("<?php echo $config->urls->templates?>/glb/", "Silo.glb", scene, function (scene) {
                // Create a default arc rotate camera and light.
                scene.createDefaultCameraOrLight(true, true, true);
//code              
</script>              

I am trying to work with Bablylon.js to make a 3d comic on my Processwire site, but I need to pass a directory to the Bablylon scene loader inside of a string in the Bablylon Javascript function.

How do I tell Babylon to locate the file correctly while referencing Processwire's template directory through php?

Below is the documentation for the Bablylon Append method.

Static Append

Find examples in Playground

Link to comment
Share on other sites

<script>
//code  

<?php $glb = echo $config->urls->templates.'/glb' ?>       
            // Append glTF model to scene.
            BABYLON.SceneLoader.Append(<?php $glb?>, "Silo.glb", scene, function (scene) {
                // Create a default arc rotate camera and light.
                scene.createDefaultCameraOrLight(true, true, true);
  
//code
</script>  

Could something like this work?

Link to comment
Share on other sites

1 hour ago, gbball said:

BABYLON.SceneLoader.Append(<?php $glb?>, "Silo.glb", scene, function (scene) {

You are missing an echo: <?php echo $glb?>

1 hour ago, gbball said:

echo $config->urls->templates.'/glb'

No big deal but "/" is not needed as the config value ends in that.

1 hour ago, gbball said:

Could something like this work?

I don't know what the JS code does but generating bits of it with PHP should work ?

  • Like 2
Link to comment
Share on other sites

1 hour ago, szabesz said:

You are missing an echo: <?php echo $glb?>

No big deal but "/" is not needed as the config value ends in that.

I don't know what the JS code does but generating bits of it with PHP should work ?

Thanks!  I'll give it a try!

  • Like 1
Link to comment
Share on other sites

18 hours ago, gbball said:

<?php $glb = echo $config->urls->templates.'/glb' ?>

Just one more thing I noticed in the code above: you do not need echo in this expression as assigning the ULR to the variable just works without it.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...