Best PHP Technologies for Templating?

I want to create my own template layer in php as part of my OOP Framework, but Im looking for such an example of how to do this properly. I would like to avoid parsing each html file to find comments that tell the template what to do, but rather use a faster / cleaner / modern technique. I just need some examples, because I looked around using Google, and nothing caught my eye. I am trying to separate my presentation and logic, but what I do requires a ton of logic through HTML.

thanks

PS I do not want to use an existing template engine, such as smarty, I want to create my own.

+3
source share
5 answers

I will ask the same question about you that I will ask someone offering Smarty:

Why do you want to add a template language to PHP, which is a template language?

PHP is a template language. I think that people forget about it or try to consider it as a pure OO language, which is not . Play with the strengths of PHP. Do not try to do something wrong.

To keep it all said, it’s difficult to answer your question because you don’t say how simple or complex your template system is, namely, what functions you intend to support.

, . . , , . .

, :

{:...:}

, HTML ( , .

. , , , , , :

{:if ...:}
Some conditional content
{:endif:}

? - :

{:if *some condition*:}
{:if *some other condition*:}
Some other conditional content
{:endif:}
Some conditional content
{:endif:}

, .

+14

Model-View-Controller? ( ) . .

P.S: PHPTAL (Language Attribute Language). , html- , html, .

, .

+5

- php , php . , , php ( ). , , ( ) .

, , 3 , ...

  • (strpos, substr ..). , . .

  • . , . , , .

  • , - phken tokenizer...

  • DOM -extension! xhtml xml. , ! ,


      <loop item="$myVariable" times="$x">
        <print name="$myVariable->name" entities="yes" nl2br="yes" purify="removeemptytags, xss"/>
        <hr/>
      </loop>

smarty, imho. ( - node $x ), , , php (smarty ).

, , - ( , )


    <!-- begin loop:myVariable -->
      <-- print:myVariable->name() -->
      <hr/>
    <!-- end loop -->

, DOM , moar, PHP- / html ( , , , carmack skeet, ).

.

+1

... , , html code....

, ...

, ? , , , , ? , , . , , , , , , - , - .

0

You will need to implement parsers. But instead of analyzing it every time, they do what Smarty and others save the analyzed output for later use. It would be even better if the output of your parser is the PHP code itself.

0
source

Source: https://habr.com/ru/post/1707128/


All Articles