I have a list and when somebody clicks on an item in the list it will display a div to enter some information. Each div that gets displayed can contain different information. Is it better to load the divs using Yii’s renderPartial or load all of the divs in the same view and use JavaScript to toggle them on or off?
view.php
<li><?php echo CHtml::ajaxLink('FaceBook', array('social/showFaceBook', 'title'=>$itemmodel->title, 'price'=>$itemmodel->price), array('update' => '#facebook-content')); ?></li>
<li><?php echo CHtml::ajaxLink('Twitter', array('social/showTwitter'), array('update' => '#twitter-content')); ?></li>
<div id="facebook-content"></div>
<div id="twitter-content"></div>
SocialController.php
public function actionShowTwitter() {
$this->renderPartial('_twitter');
}
public function actionShowFaceBook($title, $price) {
$this->renderPartial('_facebook', array('title'=>$title, 'price'=>$price));
}
_twitter.php (_facebook.php is very similar)
<h3>Twitter</h3>
<ul>
<li><label>Message</label><textarea></textarea></li>
</ul>
<button>Delete</button>
The other option is instead of having different renderPartial files all of the HTML would be in view.php. I would use jquery to hide/show the facebook-content and twitter-content divs when clicking on the <li>Facebook</li> or Twitter link.