0

I am using laravel 5. I am construction a attachments list using jquery.

my file path is /files/myfile.jpg

      $('#attachmentList').empty();
            $.each(response, function(key, val) {
                $('<li><a href="{{ asset('+val.filepath+val.filename+') }}">'
                  +val.filename+'</a></li>').appendTo('#attachmentList');
            });

this creates %7B%7B%asset(files/myfile.jpg)%20%7D%7D url in my address bar.

I need asset url in the hyperlink. How can I make hyperlink in my view.

3
  • 1
    Why will server side templating syntax work from the client side? Create a fully qualified asset URL from the server before sending it to the client side. Commented Jun 17, 2015 at 5:40
  • I don't know how to do that? :( Could you explain that? Commented Jun 17, 2015 at 5:41
  • 1
    Use the URL::asset helper in the controller from where you are sending these file paths. It would be best to post the controller code to which you are making your AJAX call. Commented Jun 17, 2015 at 5:45

1 Answer 1

1

You need to use the other Blade syntax.

  $('#attachmentList').empty();
        $.each(response, function(key, val) {
            $('<li><a href="{!! asset('+val.filepath+val.filename+') !!}">'
              +val.filename+'</a></li>').appendTo('#attachmentList');
        });
Sign up to request clarification or add additional context in comments.

1 Comment

Your syntax doesn't look correct. Did you really expect it to work when you use Javascript variable inside a PHP block? I only answered for the character escaping problem.

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.