I was in need of a way to wrap some HTML around view outputs, if
needed, thus stopping me from adding the wrapper code to the layout.
This was for a templating issue I was having.

So after spending some time looking through Cakes View class, I cam up
with the code below, hope it helps someone else.

<?php
        class WrapperHelper extends AppHelper {

                public function afterRender() {
                        $post = ob_get_flush();
                        while(ob_get_level() > 0) {
                                ob_end_clean();
                        }
                        $post = "
                        <div class=\"post\">
                                <div class=\"post-body\">
                                        <div class=\"post-inner article\">
                                                $post
                                        </div>
                                        <div class=\"cleared\"></div>
                                </div>
                        </div>
                        ";
                        ob_start();
                        echo $post;
                }
        }
?>

What it does is this: capture the output buffer, clean all buffers,
modify the rendered view, start output buffering again and echo out
the modified view.

Puk!

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

Reply via email to