V
V
Vitaly2018-10-20 01:25:05
PHP
Vitaly, 2018-10-20 01:25:05

Is there a way to convert pug to twig?

Hello. Tell me if someone has come across the need to convert PUG to TWIG. Found
this package, PugToTwig but can't get it to work properly.
Example PUG code from link:
pug.test

ul#users
  - for user in users
    li.user
      // comment
      = user.name
      | Email: #{user.email}
      a(href=user.url) Home page

Next, you need to convert this code to twig using PHP . I save the data and try to output it to twig. As a result, everything remains the same in the source code of the browser
PugToTwig::convert(file_get_contents('test.pug'));
<ul id="users">
  {% for user in users %}
    <li class="user">
      {#  comment #}
      {{ user.name | e }}
      Email: {{ user.email | e }}
      <a href="{{ user.url | e }}">Home page</a>
    </li>
  {% endfor %}
</ul>

All constructs twig-a treats as strings, it does not process any of this.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Eugene Pukha, 2018-10-20
@Seahunter

You wanted to get a twig template, you got it. Now is the time to feed it to the twig template engine, which will render the html from the resulting twig template.
Have you tried looking towards twig.js , so that the layout is already in the twig templates?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question