1

Trying to implement this jquery plugin http://www.myjqueryplugins.com/jquery-plugin/jrating i have trouble setting paths for stars in js file. its not possible to use php inside js file right? Cause I need to set those stars path to be inside webroot folder and i don't know how to do that without WWW_ROOT constant

(function($) {
    $.fn.jRating = function(op) {
        var defaults = {
            bigStarsPath : 'icons/stars.png'
            ...

3 Answers 3

4

Just make it an absolute URL instead of a relative URL:

(function($) {
$.fn.jRating = function(op) {
    var defaults = {
        bigStarsPath : '/icons/stars.png'  //<-- notice the "/" before "icons"
        ...

That tells it to look for an 'icons' folder within the 'webroot' folder.

The same goes for any other files in the webroot. Sometimes you want to include css or javascript file that's within a library or something - in that case, you can include it by setting a "/" first - like this: /bootstrap/js/main.js.

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

Comments

1

There are many solutions:

  1. Copy this code to view file (.ctp) and use:

    bigStarsPath: '<?php echo $path_to_file; ?>'
    
  2. If You can add .js files to preprocessor of PHP: Parse a JavaScript file through PHP

  3. Set in view js variable and read in js.

Comments

1

in your header file put this code below script with set constant variable and use that JavaScript variable name called bipartisanship in your JS file, JS must be include after this code.

&lt;?php define('bipartisanship','/icons'); ?&gt;
    &lt;script type="text/javascript"&gt;
        var bipartisanship = '&lt;?php echo bipartisanship; ?&gt;'
    &lt;/script>

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.