Change Form of HTML ourput

#37 · closed · 4 comments

View on GitHub ↗

t-book

Dear Grégoire, thanks a lot for this great peace of code. I´m unsure if this is the right place to ask if not please just close/ignore this issue. **My question is:** As far as I can see /HTML/Document [renderDocument()](https://github.com/Gregwar/RST/blob/master/HTML/Document.php#L21) is responsible for the html structure. Further it´s possible to inject css and js in each file. But what would be your recommend way if this HTML structure does not fit my needs? Let´s say I would like to inlude the TOC in every file or to have only the body rendered without head tag .. to include the files in other templates? Here are my Ideas where but I´m unsure which way to go: - there is already a setter in your code to overwrite HTML output I do not know of. - exend f.e.: RST/Builder.php to use an extended HTML/Document.php? - Fork and change the [renderDocument()](https://github.com/Gregwar/RST/blob/master/HTML/Document.php#L21) f.e. by use of external templates. Happy about your input! Cheers and merry christmas ;) Toni

Comments

Gregwar

Hello, You can also use the Kernel pattern that is used here: 1) Create your own `Document` class that inherits `HTML/Document` with your custom logics 2) Create your own `Kernel` that inherits `HTML/Kernel` and override the `getClass` method to something like: ```php <?php use Gregwar\RST\HTML\Kernel; class MyCustomKernel extends Kernel { public function getClass($name) { if ($name == 'Document') { return MyCustomDocument::class; } else { return parent::getClass($name); } } } ``` 3) Create your parser or your builder using your custom Kernel (first argument for Builder and 2nd argument for Parser) Note that the same thing can be done to redefine any Node or Directive behaviour

Gregwar

(The so-called "Kernel" here is actually a Factory)

Gregwar

Also, may I mention Slidey, a projet I done (that was the motivation for RST) using this library for my PHP lecture that does the same thing (custom Kernel): https://github.com/Gregwar/Slidey/blob/master/Kernel.php c.f https://github.com/Gregwar/PHP http://gregwar.com/php/

t-book

+1 big thanks Grégoire! I will follow your suggestion and try my luck! best, toni