Functionality First Or Template First

hi i just started yii development and i am still learning. can some one guide me if its better idea to develop all functionality of the yii app first then write HTML template for that app

or

its better to have some HTML template first and then override widgets html markup to match your template.

I started with 2nd approach and now having troubles with the widgets like "CListview", "CDetailview" etc, since their HTML output is not according to my HTML template.

Help plz

thanks…