Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

How to execute volt syntax in js file

Hello phalcon community. I want to know the solution how to execute volt syntax in js file . if attach javascript syntax in file like index.volt it's work fine

example. I have index.volt in this file. I write javascript like this




$('.chk_box').attr('checked', false);

var html = '';
var path = '{{url()}}';
    url: '{{url("groupusers/card")}}',
    type: 'GET',
    data: {value: groupId},
.done(function(res) {
    if(res != 'new'){
        var path = '{{url("groupusers/previewcard/'+groupId+'")}}';
        var btn = '<a href="'+path+'" class="btn btn-warning" target="_blank" id="previewCard">Preview</a>';

        $('#description_card').val(res.card_description );

        $("input[name='check_btn'][value='" + res.card_path + "']").attr('checked', true);


it can work when I write in index.volt but I try to save this script to script.js and attach in to index.volt it can't interpreter variable

var path = '{{url()}}';

Please give me an introduction or solution to resolv this problem. thank you p.s. sorry for my bad english


I found the solution to resolv this problem. I declare global variable in javascript because I want to use only url() variable in volt template so this solution is works to me . thank you

 var $gp =  window.location.pathname.split( '/' );
 var $path = '/'+gp[1]+'/';