I
I
igor_solweb2020-10-14 11:56:00
PHP
igor_solweb, 2020-10-14 11:56:00

Why is the php request not being interpolated in the image path of the Vue component?

Good afternoon, it seems like a banal problem, but I can’t understand why when I register in the vue component in the template

<img src="<?php echo get_template_directory_uri() ?>/img/icons/icon.svg" alt="icon">

then no interpolation takes place.

I know that php code is not written in js, but I have vue code.
tell me where to look and how to correctly implement access to a static image on the server, so as not to prescribe the entire path.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey delphinpro, 2020-10-14
@igor_solweb

Somewhere in the header of the page in the template

<script>
  window.tplDir = '<?php echo get_template_directory_uri() ?>';
</script>

and in the component
<img
  :src="window.tplDir + '/img/icons/icon.svg'"
  alt="icon"
>

F
FanatPHP, 2020-10-14
@FanatPHP

because php code is not written in js.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question