Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

acacha's avatar

Vue: using templates from external file

I doesn't achive to work using a template as a external file with:

<script id="tree-table-template" type="x-template"  src="http://midomain.com/templates/vue/tree_table_template.tpl"></script>

Is that possible?

0 likes
8 replies
acacha's avatar

Finally I used Browserify with partialify to require external files like css o js using node.js style (using require). See example at:

https://github.com/vuejs/vue-browserify-example

I prefer using a folder for each component than vueify aproach (an unique file for every component). Partialify give me more flexibility structuring my components and having css, js, html mixed in one file it's a bit confusing for editors like PHPStorm.

2 likes
Hebilicious's avatar
Level 2

If you use laravel-elixir and the mix.browserify method everything you need come out of the box. So you can structure stuff like :

component.js

module.export = {
template: require('./templates/template.html'),
data: function(){
    return {
    text: "Hello World!"
    };
}
};

template.html

<h1>{{ text }}<h1>

Regarding .vue syntax, you can use https://github.com/vuejs/vue-syntax-highlight with php storm iirc. Using vueify/vue-loader is really handy, the hot-reload and scoped css features are really worth it, and it plays really well with pre-processor.

4 likes
excellentingenuity's avatar

Any one know a way to use a blade template for the vue template so you would have:

module.export = { template: require('./templates/template.blade.php'),

and in the blade template we could access all the blade goodness like the csrf token etc?

Please or to participate in this conversation.