The solution would have to be a bit more elaborate.
On the main page:
Put the PHP part that processes the variables at the beginning of the script, and add something like this in the PHP part :
$esquerda = $imagens_links_base . $imagens_links['seta-esquerda'];
$direita = $imagens_links_base . $imagens_links['seta-direita'];
And, in the HTML part that calls the previous JS, modified:
Assuming the original is like this:
<script src="/scripts/meuScript.js"></script>
You change to
<?php
// notar que mudamos o .js pra .php:
echo '<script src="scripts/meuScript.php?esquerda=';
echo urlencode( $esquerda ) . '"&direita="' . urlencode( $direita );
echo '"></script>';
?>
Note that the order of the code in this case is important. Your PHP has to produce the correct variables before this <script>
, which may give some work depending on how your code is today.
in your JavaScript:
First, rename the .js script to .php, so that it is rendered on the server.
Add these lines at the beginning of the script:
<?php
$esquerda = $_GET['esquerda'];
$direita = $_GET['direita' ];
?>
These lines will extract the paths mounted by the main page, and put them in the variables $esquerda
and $direita
, to facilitate the next part.
Then change the lines mentioned this way:
slider.append('<div class="nivo-directionNav">
<a class="nivo-prevNav"><img class="seta-esquerda" src="<?php echo $esquerda; ?>" /></a>
<a class="nivo-nextNav"><img class="seta-direita" src="<?php echo $direita; ?>" /></a>
</div>');
Brief explanation:
JavaScript runs in the browser, and PHP runs on the server. They are completely separate languages and concepts.
The proposed solution does the following: First, on the main page, we send all PHP-processed paths to the JS file as part of the URL.
Then, by renaming the JS file to PHP, we get it processed on the server, and the variables sent in the URL will be inserted in the JS part, and then sent the result to the browser with the path correct already being part of the source, as if it had been typed. The browser is not even aware of PHP.
Important: Surely you have a thousand more elegant ways to solve this problem, the biggest intention of the response was to "force the bar" for the thing to work the way you are imagining > Now, forgetting that solution and rethinking the thing in the right order and separating the tasks from each language would be the right way.