Support » Requests and Feedback » Why WordPress doesn’t support Twig in the core?

  • Đăng Tú

    (@ngdangtu)


    Twig seems to be a promising template engine that FE WP dev could really use. But, until now, all we have is an plugin for it. I wonder why?

Viewing 8 replies - 1 through 8 (of 8 total)
  • Joy

    (@joyously)

    You could say the same of 100 other subjects. It comes down to 1) does core have a use for it itself?, and 2) would it benefit 80% of users?

    Đăng Tú

    (@ngdangtu)

    I can’t really answer the first question, but for the second, that is me. I’ve always thought that template engine is not a good way for practice until I found myself in a business case. Where time is valuable, readable code and structure is required because I didn’t make project alone.

    And I can say, 80% FE devs ain’t make theme for fun. If FE dev is also considering as human.user

    • This reply was modified 2 months ago by  Đăng Tú.
    catacaustic

    (@catacaustic)

    But.. why Twig? Why not Smarty? Why not Blade? Why not … any other of the 100’s out there?

    The problem is that if you asked 100 developers, they’d want 99 different templating engines, and that’s never going to be maintainable.

    Out of the box, PHP can be it’s own “sort of” templating engine using <?php ?> tags mixed in with HTML, so adding another templating system on top of that actualyl maeks things slower in most cases.

    There is a fair amount of overhead when using a template engine, and templating languages can be just as daunting as PHP.

    I personally prefer to use the HEREDOC syntax built into PHP. It provides many of the benefits of a template engine, and it’s faster and infinitely more readable than mixing <?php structures in HTML (aka “spaghetti code”). Info:

    https://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc

    HEREDOCs (and template engines) have some limitations in WordPress because WP was built to use spaghetti code. Many of its functions echo their output by default, and some of these functions do not have the ability to return the same output. the_content() and get_the_content() is the most notable example.

    @catacaustic I see, it makes sense. I really have idea that Smarty was exist until now =)). About blade, it is sure a sweet syntax, but until now, I don’t really know why none makes blade plugin for WP, only Twig (Timber). Because of that, I thought maybe WP engine could get alone with Twig (sorry for childish thinking LOL).

    @diondesigns I personally don’t really like HEREDOC, it breaks the indent style in the code which is not my style.

    And to be honest, Twig is still not the best engine I would prefer to use. Somehow, I was more enjoy the OOP style like it DOM of Js. I was tried to use that one in WP but like DionDesigns said, it doesn’t play well with the spaghetti code style of PHP (even though DOM class also made by PHP team)

    @ngdangtu PHP 7.3 cleaned up the formatting of HEREDOCs. And I’m sure you agree that HEREDOCs are a better solution than spaghetti code. 🙂

    @diondesigns That is one I can’t denies =)) btw, you said “PHP 7.3 has cleaned up the formatting of HEREDOCs”. What does that means? Is this one: https://eidson.info/post/php-flexible-heredoc-nowdoc-syntax

    Cool.

    • This reply was modified 1 month, 4 weeks ago by  Đăng Tú.
Viewing 8 replies - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.