Render View Without Layout CSS

I made an user email configurable template, where the user can enter the color and logo for his email.

I try to offer a preview of the email.


<?php $this->beginContent('//emailTemplate/mainTemplate'); ?>


        Phasellus dictum sapien a neque luctus cursus. Pellentesque sem dolor, fringilla et pharetra vitae. consequat vel lacus. Sed iaculis pulvinar ligula, ornare fringilla ante viverra et. In hac habitasse platea dictumst. Donec vel orci mi, eu congue justo. Integer eget odio est, eget malesuada lorem. Aenean sed tellus dui, vitae viverra risus. Nullam massa sapien, pulvinar eleifend fringilla id, convallis eget nisi. Mauris a sagittis dui. Pellentesque non lacinia mi. Fusce sit amet libero sit amet erat venenatis sollicitudin vitae vel eros. Cras nunc sapien, interdum sit amet porttitor ut, congue quis urna.


<?php $this->endContent(); ?>

views/emailTemplate/mainTemplate.php (simplified version for exemple)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="">


<!-- If you delete this meta tag, Half Life 3 will never be released. -->

<meta name="viewport" content="width=device-width" />

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />


<link rel="stylesheet" type="text/css" href="<?php echo Tenant::trimEditor(Yii::app()->createAbsoluteUrl("/css/emailTemplate.css")); ?>" />


<body bgcolor="<?php //I echo the body color ?>">

<?php echo $content; ?>	



[color="#FF0000"]But either the css in the email overwrites the site layout or the site overwrites the email template…[/color]

[color="#006400"]How can I contain the css of the email to its view? iFrames?[/color]

You could remove the link tag from your mainTemplate.php file

and add clientScript to your preview.php file:

<?php Yii::app()->clientScript->registerLinkTag("stylesheet", "text/css", Tenant::trimEditor(Yii::app()->createAbsoluteUrl("/css/emailTemplate.css"))); ?>