BT

XHP-Bootstrap Project Announced, Combines XHP with Bootstrap Framework

| by James Chesters Follow 2 Followers on Oct 29, 2014. Estimated reading time: 2 minutes |

Fred Emmott, software engineer for Facebook, has announced the release of XHP-Bootstrap project, combining XHP with the Bootstrap framework.

In the article "Using XHP with Bootstrap", Emmott describes XHP as a way to create HTML user interfaces from PHP or Hack, and provides an XML-like syntax for creating stringable objects representing markup.

Emmott gives a simple drop down menu as an example, as below:

print
  <bootstrap:dropdown>
    <bootstrap:button>
      Dropdown
      <bootstrap:caret />
    </bootstrap:button>
    <bootstrap:dropdown:menu>
      <bootstrap:dropdown:item href="#">
        Foo
      </bootstrap:dropdown:item>
      <bootstrap:dropdown:item href="#">
        Bar
      </bootstrap:dropdown:item>
      <bootstrap:dropdown:item disabled="true" href="#">
        Disabled
      </bootstrap:dropdown:item>
    </bootstrap:dropdown:menu>
  </bootstrap:dropdown>;

This produces the following:

Emmott summarises the advantages of XMP-Bootstrap. Among them include "Semantic markup (server-side)", where "the element name describes exactly what it is, instead of everything being a <div> or <span> with the meaning being hidden in a class".

Also of note is XHP-Bootstrap's "easier upgrade path". In this instance, XHP-Bootstrap can automatically use the new behaviour with no changes to the code if Bootstrap makes incompatible changes or current behaviour becomes deprecated.

Emmott describes the project as being "well loved" by Facebook's frontend engineers, however some responses from the community to the announcement has been, in places, mixed.

On Reddit, in the discussion Using XHP With Bootstrap user McGlockenshire asked:

Has anyone used XHP for a live site? What are your impressions of it? After years of pure-PHP templates, I recently tried out Twig and rather enjoyed it. I've been thinking about exploring other template options, but haven't had the courage to try out XHP yet.

User gou1 replied

I haven't tried XHP yet, but it does seem pretty useful for composing elements. My only complaint would be namespacing and composer integration which seem pretty off by todays' standards.

I was looking for a templating system with the features of something like Twig, without the need for learning a syntax and came accross League\Plates which does exactly that.

XHP, Twig, Plates: Smarty days are long gone and PHP now offer really interesting templating solutions

Emmott responded that Namespacing was "definitely an issue" for XHP-Bootstrap.

In the same discussion, user recycledheart was more verbose in their feedback. They said:

The definition of insanity is doing the same thing over and over and expecting different results.

How does this help? How does any add-on templating system simplify anything? This statement is in earnest; I just don't see the point. The 'designer' vs 'developer' argument is invalid. If you're not interpolating logic in your templates, which you shouldn't be, its a moot point.

How is <?=$foo?> any more complicated to understand or implement than {$foo} ?

Or {foreach from=$haystack item=$needle}...{/foreach} than <? foreach($haystack as $needle){ ... }?>

Emmott explained: "If the first example is meant to be XHP: <?=$foo?> is likely to be an XSS hole. {$foo} is safe."

On the GitHub project page, Emmott says he wants to make contributing to the project "as easy and transparent as possible" for the community. For more information on submitting pull requests, anyone interested in being part of the project should visit the "CONTRIBUTING.md" page.

Rate this Article

Adoption Stage
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread
Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Discuss
BT