## Overview
To create a view use
$view = new WPDKView( 'my-view' );
$view->content = 'Hello World";
$view->display();
Or
$view = WPDKView::initWithContent( 'my-view', '', 'Hello World' );
$view->display();
Or, suggested method
class MyView extends WPDKView {
public function __construct() {
parent::__construct( 'my-id', 'additional class' );
}
Override
public function draw() {
echo 'Hello World';
}
}
### draw() VS content
If you like use a WPDKView directly, you will use the content property. Otherwise, you can sub class the WPDKView
and then use the method draw() to diplay the content of the view.
### Observing
You can observe some event via filters and actions. For example you can catch when a content has been drawed.
For fo this you can use the filter wpdk_view_did_draw_content:
add_action( 'wpdk_view_did_draw_content', array( $this, 'wpdk_view_did_draw_content') );
public function wpdk_view_did_draw_content( $view ) {
if ( is_a( $view, 'WPDKHeaderView' ) ) {
Do something
}
}
In this case we had used the "is_a" function to understand which type of view was passed. Alternatively you can check
the view id, for example.
public function wpdk_view_did_draw_content( $view ) {
if ( 'my_id' == $view->id ) {
Do something
}
}