Is it possible to write PHP in jade/pug?

前端 未结 5 2324
挽巷
挽巷 2021-02-09 11:37

Is it possible? If so, how? If its not, do I have to abandon pug if I need to write PHP in my documents? After searching around I didnt find anyone that has adressed this.

5条回答
  •  没有蜡笔的小新
    2021-02-09 11:44

    Since PHP doesn't care whether the "outside" code is HTML or really anything specific, you could simply use PHP as you normally would and have it output Pug-formatted code instead of HTML. For instance:

    myPugTemplate.pug.php

    html
      head
        title "title ?>"
      body
        foo) {
            echo $indent . 'bar= myPost';
          } else {
            echo $indent . 'baz= myNav';
          }
        ?>
        footer
          +footerContent
    

    And if your Pug is processed on the server then you'd also include a Pug-processing step, for instance if you use Apache you could use mod_ext_filter configured in such fashion with pug-cli installed:

    ExtFilterDefine pug-to-html mode=output intype=text/pug outtype=text/html \
      cmd="pug"
    
    
      SetOutputFilter pug-to-html
    
    

提交回复
热议问题