L
L
LoveCode &Coffe2020-01-07 23:00:29
PHP
LoveCode &Coffe, 2020-01-07 23:00:29

Is it possible to insert php code into the handlebars template engine??

I'm going to start making a website for a person tomorrow. For the control system, you need to use webasyst (shop-script). I myself am more friends with the front, but in pxp + - se. And then such a strange idea came to me after the holidays. I read a little to the doc. The input file is essentially index.html to which other pages are connected via php. Is it possible to deploy all this as a spa application? (at least only the front without the admin panel) like this:
Connect webpack
Set up the index.htm input file (you get the input file of the theme being developed)
Set up the index.js input file (well, as usual, modules will be connected to it and it will be built in bundle js)
ps and I think js with a default theme to connect to it
All additional pages will be rewritten using the handlebars templating engine.
And here, so as not to lose the cms structure. I would like to do this (if possible):
Have a header.hbs template

<div id="header">
    <?php echo '<h1>Привет, мир!</h1>'; ?>
  </div>

and then in 2 js files (vanilla js)
header.js
import  headerTemplate from {тут путь до header.hbs}
const Header = () => document.getElementById('app').innerHTML = headerTemplate()

and home.js
import  Header from  {тут путь до header.js}
//render header
Header()

In general, it seems like hbs, it is intended only for data output (it seems like only in string format), but can you somehow contrive?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Belyaev, 2020-01-08
@bingo347

Handlebars template is processed at compile-time
At run-time there will be just a js function that takes a context object as input and returns a string.
Therefore, no php in the template will be executed

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question