Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP - Looking for an HTML Generator/Manager [closed]

Tags:

html

php

I'm trying to find a tool that I can use to generate markup programatically (non-irl word). Here is an example of what I'm trying to accomplish in pseudo-code...

$htmlDoc = new HTML_Document();

$htmlDoc->setTitle('Cool Title');

$htmlDoc->addJs('some_js_file.js');
$htmlDoc->addStylesheet('some_css_file.css');

$divElement = new HTML_Element_Div();
$htmlDoc->append('body', $divElement);

$output = $htmlDoc->generate();

What is the best tool for this?

like image 297
John Himmelman Avatar asked Aug 23 '26 19:08

John Himmelman


2 Answers

I'm working on a simple DSL that addresses this common task. It's called htmlgen, mirrored on packagist.

Here's an example -

use function htmlgen\html as h;

h('#wrapper',
  h('h1.title', 'Hello, World'),
  h('p',
    h('comment', 'link to something'),
    h('a', ['href'=>'https://duckduckgo.com'], 'search the internet')
  )
);

Here's the output (actual output does not have whitespace)

<div id="wrapper">
  <h1 class="title">Hello, World</h1>
  <p>
    <!-- link to something -->
    <a href="https://duckduckgo.com">search the internet</a>
  </p>
</div>

It's very new but at ~200 lines of source, it's already very powerful. Fork it and make adjustments or send me a note with suggestions.

like image 130
Mulan Avatar answered Aug 25 '26 10:08

Mulan


There's one bundled as standard in PHP: http://php.net/manual/en/book.dom.php

C.

like image 24
symcbean Avatar answered Aug 25 '26 10:08

symcbean



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!