<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Mellow Morning &#187; Css</title>
	<atom:link href="http://www.mellowmorning.com/category/css/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mellowmorning.com</link>
	<description>Blogging the world of IT and Business</description>
	<lastBuildDate>Wed, 01 Feb 2012 19:00:15 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Django Facebook 2.0 &#8211; Integrating Facebook</title>
		<link>http://www.mellowmorning.com/2011/06/23/django-facebook-2-0-integrating-facebook/</link>
		<comments>http://www.mellowmorning.com/2011/06/23/django-facebook-2-0-integrating-facebook/#comments</comments>
		<pubDate>Thu, 23 Jun 2011 15:18:40 +0000</pubDate>
		<dc:creator>tschellenbach</dc:creator>
				<category><![CDATA[Css]]></category>
		<category><![CDATA[Django]]></category>
		<category><![CDATA[Events]]></category>
		<category><![CDATA[Facebook]]></category>
		<category><![CDATA[Fashiolista]]></category>
		<category><![CDATA[Prototype]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[django facebook]]></category>
		<category><![CDATA[Facebook connect]]></category>
		<category><![CDATA[Facebook login]]></category>
		<category><![CDATA[Facebook registration]]></category>
		<category><![CDATA[facebook sdk]]></category>
		<category><![CDATA[open graph]]></category>
		<category><![CDATA[Social authentication]]></category>

		<guid isPermaLink="false">http://www.mellowmorning.com/?p=350</guid>
		<description><![CDATA[It&#8217;s been a year since Facebook changed the web with the open graph API and their like button. Unfortunately Facebook didn&#8217;t have much developer love for the python/django platform. Django Facebook aims to make it easy to build facebook apps and integrate facebook with your website.
Key functionality
One of the strong points of Django Facebook is [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s been a year since Facebook changed the web with the open graph API and their like button. Unfortunately Facebook didn&#8217;t have much <a href="http://developers.facebook.com/blog/post/417/">developer love</a> for the python/django platform. <a href="https://github.com/tschellenbach/Django-facebook">Django Facebook</a> aims to make it easy to build facebook apps and integrate facebook with your website.</p>
<h3>Key functionality</h3>
<p>One of the strong points of Django Facebook is the ability to register users using Facebook. It ports all of Facebook&#8217;s user data to the Django user and profile models. This allows you to have a secure register/connect/login flow using Facebook, greatly reducing the barriers to start using your application. Below an example of me registering for Fashiolista using the <a href="http://www.fashiolista.com/intro_wide/">Facebook register flow</a>. </p>
<p style="text-align: center;"><b>Me on Facebook</b><br /><img class="size-full wp-image-366 aligncenter" title="thierry_facebook" src="http://www.mellowmorning.com/wp-content/uploads/2011/05/thierry_facebook.png" alt="" width="569" height="196" /></p>
<p style="text-align: center;"><b>Me on Fashiolista</b><br /><img class="size-full wp-image-367 aligncenter" title="thierry_fashiolista" src="http://www.mellowmorning.com/wp-content/uploads/2011/05/thierry_fashiolista.png" alt="" width="499" height="284" /></p>
<p>In this blog post I will explain how to get started implementing a Facebook connect flow. Django Facebook can however do quite a bit more, as you can see in the feature list below. Development over at the <a href="https://github.com/tschellenbach/Django-facebook">github repo</a> is very active. I strongly appreciate help on improving the functionality so please fork and contribute.</p>
<p><b>Features</b></p>
<ul>
<li>Register users using the Facebook open graph API
<ul>
<li>Full profile data birthday, gender, website, about me, username, email and picture</li>
<li>Support for mobile authentication</li>
<li>Fallback to registration form for entering additional data when required</li>
</ul>
</li>
<li>Build Facebook Canvas applications</li>
<li>Mobile registration using Facebook</li>
<li>Execute Facebook FQL queries</li>
<li>Upload pictures to Facebook</li>
<li>Find your Facebook friends</li>
</ul>
<h3>Getting Started</h3>
<p>Now let&#8217;s get started with building a Facebook login/connect/register flow. This post will guide you through it step by step.</p>
<h4>Prerequisites</h4>
<p><a href="http://www.facebook.com/developers/createapp.php" target="_blank">Create a Facebook app</a></p>
<p><a href="https://bitbucket.org/ubernostrum/django-registration/" target="_blank">Have django registration installed</a> (other registration systems will require some small code changes)</p>
<p>pip install django_facebook :)</p>
<h4>A.) Settings and more</h4>
<p>Define these settings in your settings file.<br />
FACEBOOK_API_KEY<br />
FACEBOOK_APP_ID<br />
FACEBOOK_APP_SECRET</p>
<p>add django facebook to your installed apps<br />
&#8216;django_facebook&#8217;,<br />
add this line to your url config<br />
(r&#8217;^facebook/&#8217;, include(&#8216;django_facebook.urls&#8217;)),<br />
add this line to your context processors<br />
&#8216;django_facebook.context_processors.facebook&#8217;,<br />
add this to your AUTHENTICATION_BACKENDS<br />
&#8216;django_facebook.auth_backends.FacebookBackend&#8217;,</p>
<h4>B.) Adjust your user Profile model</h4>
<p>Secondly we need to be able to store the Facebook data on your user profile.<br />
The easiest way to do this is to add the abstract model in django_facebook/models.py called FacebookProfileModel to your profile model.<br />
After your profile is ready to store Facebook data you should have a working example at /facebook/connect/.<br />
Let me know in the comments if something went wrong up to this point :)</p>
<h4>C.) Design and integration</h4>
<p>You can style the facebook form and button anyway you see fit. <a href="http://www.fashiolista.com/intro_wide/">Over at Fashiolista</a> we added a nice facepile for example. The basic markup is located in the example file connect.html.<br />
We use the facebook javascript SDK for a smooth user integration. You can load the facebook JS like this:</p>
<pre class="javascript" name="code">&lt;script src="{{ MEDIA_URL }}js/original/facebook.js" type="text/javascript"&gt;&lt;/script&gt;
&lt;script&gt;
facebookAppId = '{{ FACEBOOK_APP_ID }}';
function facebookJSLoaded(){
FB.init({appId: facebookAppId, status: false, cookie: true, xfbml: true});
}
window.fbAsyncInit = facebookJSLoaded;
F = new facebookClass(facebookAppId);
F.load();
&lt;/script&gt;</pre>
<p>Subsequently implement a form which calls Facebook via javascript. Note that you can control which page to go to after connect using the next input field.</p>
<pre class="python" name="code">&lt;form action="{% url facebook_connect %}?facebook_login=1" method="post"&gt;
&lt;a href="javascript:void(0);" style="font-size: 20px;" onclick="F.connect(this.parentNode);"&gt;Register, login or connect with facebook&lt;/a&gt;
&lt;input type="hidden" value="{{ request.path }}" name="next" /&gt;
&lt;/form&gt;
&lt;div id="fb-root"&gt;&lt;/div&gt;</pre>
<p>That was all, you should now have a working registration flow using Facebook. Let me know in the comments if you encounter any difficulties.<br />
If you want to go one step further and understand the facebook API, you can find the <a href="http://developers.facebook.com/docs/">Facebook documentation here</a>.<br />
Django Facebook received tons of improvements from the python community. I&#8217;m certainly missing a few authors, but I would like to thank a few specifically:</p>
<p><strong>Many thanks to (amongst many others)</strong></p>
<ul>
<li><a href="http://gigantuan.net" target="_blank">Kenneth Love</a></li>
<li><a href="http://gc-taylor.com" target="_blank">Greg Taylor</a></li>
<li><a href="http://www.linkedin.com/pub/riccardo-magliocchetti/6/ba/105" target="_blank">Riccardo Magliocchetti</a></li>
<li><a href="http://djangopeople.net/kmike/" target="_blank">Mikhail Korobov</a></li>
<li>Simple Geebus</li>
<li><a href="http://twitter.com/jonrohan" target="_blank">Jon Rohan</a></li>
<li>Rick van Hattem</li>
<li><a href="http://www.stochastictechnologies.com" target="_blank">Stochastic Technologies</a></li>
<li><a href="https://simplegeo.com/" target="_blank">Simplegeo</a></li>
<li><a href="http://www.canb.net/" target="_blank">Can Burak Cilingir</a></li>
<li>zdexter</li>
<li><a href="http://apps.facebook.com/railroadempire" target="_blank">Michael Robellard</a></li>
<li><a href="https://github.com/ramiro" target="_blank">Ramiro Morales</a></li>
</ul>
<h3>More posts coming up</h3>
<ul>
<li>Building a facebook canvas app using Django Facebook</li>
<li>Find and invite friends using Django Facebook</li>
</ul>
<h3>We&#8217;re hiring!</h3>
<p>Do you also see the beauty in clean code? Are you experienced with high scalability web apps? Currently we&#8217;re looking for additional talent over at our Amsterdam office. Feel free to drop me a line at my personal email for more information: thierryschellenbach[at]gmail.com</p>



Share and Enjoy:


	<a rel="nofollow" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.mellowmorning.com%2F2011%2F06%2F23%2Fdjango-facebook-2-0-integrating-facebook%2F&amp;title=Django%20Facebook%202.0%20-%20Integrating%20Facebook" title="Digg"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://sphinn.com/submit.php?url=http%3A%2F%2Fwww.mellowmorning.com%2F2011%2F06%2F23%2Fdjango-facebook-2-0-integrating-facebook%2F&amp;title=Django%20Facebook%202.0%20-%20Integrating%20Facebook" title="Sphinn"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/sphinn.gif" title="Sphinn" alt="Sphinn" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://del.icio.us/post?url=http%3A%2F%2Fwww.mellowmorning.com%2F2011%2F06%2F23%2Fdjango-facebook-2-0-integrating-facebook%2F&amp;title=Django%20Facebook%202.0%20-%20Integrating%20Facebook" title="del.icio.us"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.mellowmorning.com%2F2011%2F06%2F23%2Fdjango-facebook-2-0-integrating-facebook%2F&amp;t=Django%20Facebook%202.0%20-%20Integrating%20Facebook" title="Facebook"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://www.mixx.com/submit?page_url=http%3A%2F%2Fwww.mellowmorning.com%2F2011%2F06%2F23%2Fdjango-facebook-2-0-integrating-facebook%2F&amp;title=Django%20Facebook%202.0%20-%20Integrating%20Facebook" title="Mixx"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/mixx.png" title="Mixx" alt="Mixx" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fwww.mellowmorning.com%2F2011%2F06%2F23%2Fdjango-facebook-2-0-integrating-facebook%2F&amp;title=Django%20Facebook%202.0%20-%20Integrating%20Facebook" title="Google"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google" alt="Google" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.mellowmorning.com/2011/06/23/django-facebook-2-0-integrating-facebook/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>YTM launch!!</title>
		<link>http://www.mellowmorning.com/2009/12/11/ytm-launch/</link>
		<comments>http://www.mellowmorning.com/2009/12/11/ytm-launch/#comments</comments>
		<pubDate>Fri, 11 Dec 2009 16:49:51 +0000</pubDate>
		<dc:creator>tschellenbach</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[Business]]></category>
		<category><![CDATA[Css]]></category>
		<category><![CDATA[Django]]></category>
		<category><![CDATA[Dutch]]></category>
		<category><![CDATA[Events]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Prototype]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[YouTellMe]]></category>

		<guid isPermaLink="false">http://www.mellowmorning.com/?p=126</guid>
		<description><![CDATA[No more beta for YouTellMe.nl
The website which is taking over the Dutch product comparison market is officially going out of beta @ 8 o clock.
Party in Amsterdam, Keizersgracht 182 :) Festivities starting right now!

Things are going well, looking very forward to international launch.
We&#8217;ve changed a lot since the first reviews!

Beter pictures coming after the event [...]]]></description>
			<content:encoded><![CDATA[<p>No more beta for <a href="http://www.youtellme.nl/">YouTellMe.nl</a><br />
The website which is taking over the Dutch product comparison market is officially going out of beta @ 8 o clock.<br />
Party in Amsterdam, Keizersgracht 182 :) Festivities starting right now!</p>
<p><a href="http://www.mellowmorning.com/wp-content/uploads/2009/12/13342_350348980430_784785430_9966158_5558110_n.jpg"><img class="alignnone size-full wp-image-127" title="13342_350348980430_784785430_9966158_5558110_n" src="http://www.mellowmorning.com/wp-content/uploads/2009/12/13342_350348980430_784785430_9966158_5558110_n.jpg" alt="13342_350348980430_784785430_9966158_5558110_n" width="604" height="453" /></a></p>
<p>Things are going well, looking very forward to international launch.<br />
We&#8217;ve changed a lot since the <a href="http://www.nicolasleroy.fr/wp/2008/09/innovative-product-selection-on-youtellme/">first </a>reviews!</p>
<p><a href="http://www.mellowmorning.com/wp-content/uploads/2009/12/13342_350352790430_784785430_9966172_7726367_n1.jpg"><img class="alignnone size-full wp-image-129" title="13342_350352790430_784785430_9966172_7726367_n" src="http://www.mellowmorning.com/wp-content/uploads/2009/12/13342_350352790430_784785430_9966172_7726367_n1.jpg" alt="13342_350352790430_784785430_9966172_7726367_n" width="453" height="604" /></a></p>
<p>Beter pictures coming after the event :P</p>
<p>PS. Thanks to Python and Django, for enabling us to beat the competition :)</p>
<p>PSS.<a href="http://www.singel146.nl/2009/10/singel-office-warming-de-balans/" target="_blank"> Next2News, eduhub, come and join :)</a></p>



Share and Enjoy:


	<a rel="nofollow" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.mellowmorning.com%2F2009%2F12%2F11%2Fytm-launch%2F&amp;title=YTM%20launch%21%21" title="Digg"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://sphinn.com/submit.php?url=http%3A%2F%2Fwww.mellowmorning.com%2F2009%2F12%2F11%2Fytm-launch%2F&amp;title=YTM%20launch%21%21" title="Sphinn"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/sphinn.gif" title="Sphinn" alt="Sphinn" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://del.icio.us/post?url=http%3A%2F%2Fwww.mellowmorning.com%2F2009%2F12%2F11%2Fytm-launch%2F&amp;title=YTM%20launch%21%21" title="del.icio.us"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.mellowmorning.com%2F2009%2F12%2F11%2Fytm-launch%2F&amp;t=YTM%20launch%21%21" title="Facebook"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://www.mixx.com/submit?page_url=http%3A%2F%2Fwww.mellowmorning.com%2F2009%2F12%2F11%2Fytm-launch%2F&amp;title=YTM%20launch%21%21" title="Mixx"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/mixx.png" title="Mixx" alt="Mixx" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fwww.mellowmorning.com%2F2009%2F12%2F11%2Fytm-launch%2F&amp;title=YTM%20launch%21%21" title="Google"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google" alt="Google" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.mellowmorning.com/2009/12/11/ytm-launch/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>CSS Vista is great</title>
		<link>http://www.mellowmorning.com/2007/11/10/css-vista-is-great/</link>
		<comments>http://www.mellowmorning.com/2007/11/10/css-vista-is-great/#comments</comments>
		<pubDate>Sat, 10 Nov 2007 21:31:16 +0000</pubDate>
		<dc:creator>tschellenbach</dc:creator>
				<category><![CDATA[Css]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.mellowmorning.com/2007/11/10/css-vista-is-great/</guid>
		<description><![CDATA[For those trying to debug their CSS in Internet Explorer (if you still support that browser)
Have a look  at CSS vista, it is free and helped me a great deal.




Share and Enjoy:


	
	
	
	
	
	


]]></description>
			<content:encoded><![CDATA[<p>For those trying to debug their CSS in Internet Explorer (if you still support that browser)</p>
<p>Have a look  at <a href="http://litmusapp.com/labs">CSS vista</a>, it is free and helped me a great deal.<br />
<img src="http://litmusapp.com/images/labs-cssvista.gif" /></p>



Share and Enjoy:


	<a rel="nofollow" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.mellowmorning.com%2F2007%2F11%2F10%2Fcss-vista-is-great%2F&amp;title=CSS%20Vista%20is%20great" title="Digg"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://sphinn.com/submit.php?url=http%3A%2F%2Fwww.mellowmorning.com%2F2007%2F11%2F10%2Fcss-vista-is-great%2F&amp;title=CSS%20Vista%20is%20great" title="Sphinn"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/sphinn.gif" title="Sphinn" alt="Sphinn" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://del.icio.us/post?url=http%3A%2F%2Fwww.mellowmorning.com%2F2007%2F11%2F10%2Fcss-vista-is-great%2F&amp;title=CSS%20Vista%20is%20great" title="del.icio.us"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.mellowmorning.com%2F2007%2F11%2F10%2Fcss-vista-is-great%2F&amp;t=CSS%20Vista%20is%20great" title="Facebook"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://www.mixx.com/submit?page_url=http%3A%2F%2Fwww.mellowmorning.com%2F2007%2F11%2F10%2Fcss-vista-is-great%2F&amp;title=CSS%20Vista%20is%20great" title="Mixx"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/mixx.png" title="Mixx" alt="Mixx" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fwww.mellowmorning.com%2F2007%2F11%2F10%2Fcss-vista-is-great%2F&amp;title=CSS%20Vista%20is%20great" title="Google"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google" alt="Google" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.mellowmorning.com/2007/11/10/css-vista-is-great/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using php to dynamically generate conflict free css</title>
		<link>http://www.mellowmorning.com/2007/10/29/using-php-to-dynamically-generate-conflict-free-css/</link>
		<comments>http://www.mellowmorning.com/2007/10/29/using-php-to-dynamically-generate-conflict-free-css/#comments</comments>
		<pubDate>Mon, 29 Oct 2007 15:30:21 +0000</pubDate>
		<dc:creator>tschellenbach</dc:creator>
				<category><![CDATA[Css]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.mellowmorning.com/2007/10/29/using-php-to-dynamically-generate-conflict-free-css/</guid>
		<description><![CDATA[This little blog has been getting a lot of coverage lately thanks to a write up by Ajaxian. Developing with Symfony is great and always gives you a lot to think and write about.
For my new product I was having a CSS conflict. This tends to happen when you include your own html and css [...]]]></description>
			<content:encoded><![CDATA[<p>This little blog has been getting a lot of coverage lately thanks to a write up by <a href="http://ajaxian.com/archives/introducing-a-cross-site-ajax-plugin-for-prototype" target="_blank">Ajaxian</a>. Developing with Symfony is great and always gives you a lot to think and write about.</p>
<p>For my new product I was having a CSS conflict. This tends to happen when you include your own html and css into someone else&#8217;s website. For instance if you have a widget as such:</p>
<p>html</p>
<p><code>&lt;div id="mywidget"&gt;<br />
&lt;h1&gt;My hello world widget&lt;/h1&gt;<br />
&lt;/div&gt;</code></p>
<p>css</p>
<p><code>H1 {<br />
color:green;<br />
font-size:20px;<br />
}</code></p>
<p>The solution to this problem is quite straightforward, you simply specify your css selector as div#mywidget H1. However, what if you want to allow people to customize the looks of your widget. Now you could off course ask them to include the div#mywidget part, but chances are this will give problems.</p>
<p>Since I was already using the great sfCombineFilterPlugin an easy solution was available. (If you didn&#8217;t use the <a href="http://trac.symfony-project.com/wiki/sfCombineFilterPlugin">sfCombineFilterPlugin</a> yet, go check it out immediately. Also have a look at <a href="http://developer.yahoo.com/yslow/">Yahoo&#8217;s Yslow</a>)</p>
<p>The sfCombineFilterPlugin uses php to gzip, minify and cache your css and javascript. Here is how to extend that behavior to include the #mywidget specification. (Assuming you have sfCombineFilter installed)</p>
<h4>Step 1: open your .htaccess</h4>
<p>Just below the RewriteBase instruction add:<br />
<code># if we are retrieving javascript or css<br />
RewriteRule ^css/packed/prepend/(.*\.css) /sfCombineFilterPlugin/combine.php?type=css&amp;prepend=1&amp;files=$1<br />
RewriteRule ^css/packed/(.*\.css) /sfCombineFilterPlugin/combine.php?type=css&amp;files=$1<br />
RewriteRule ^js/packed/(.*\.js) /sfCombineFilterPlugin/combine.php?type=javascript&amp;files=$1</code></p>
<h4>Step 2: add this class to the top of web/sfCombineFilter/combine.php</h4>
<p>Partly based on <a href="http://www.phpclasses.org/browse/package/1289.html">CSS parser class</a>.</p>
<pre class="code">
class prependCss
{

    public static function prependCssString($str) {
        // Remove comments
        $str = preg_replace("//*(.*)?*//Usi", "", $str);

        $parts = explode("}",$str);
        if(count($parts) &gt; 0) {
            foreach($parts as $part) {
                list($keystr,$codestr) = explode("{",$part);
                $keys = explode(",",trim($keystr));
                $newkeys = array();
                if(count($keys) &gt; 0) {
                    foreach($keys as $key) {
                        if(strlen($key) &gt; 0) {
                            $key = (!strstr($key, '#mywidget')) ? '#mywidget'.$key : $key;
                            $newkeys[] = $key;
                        }
                    }
                    $keystr = implode(', ',$newkeys);
                }
                if(!empty($keystr)) //needed for spaces behind last }
                $rules[] = $keystr . " {" . $codestr . "}";
            }
            $prependedCss = implode("n", $rules);
        }
        //
        return $prependedCss;
    }

    public static function prependCssFile($filename) {
        if(file_exists($filename)) {
            return self::prependCssString(file_get_contents($filename));
        } else {
            return false;
        }
    }
}</pre>
<h4>Step 3: hack around in combine.php</h4>
<p>below $minify_js add:<br />
<code>if($_GET['prepend']==1)<br />
$prepend = true;</code></p>
<p>change the stuff below this comment to:<br />
<code>// Get contents of the files<br />
$contents = '';<br />
reset($elements);<br />
foreach ($files as $path) {<br />
if($prepend &amp;&amp; $_GET['type'] == 'css') {<br />
$contents .= "\n\n" . prependCss::prependCssFile($path);<br />
} else {<br />
$contents .= "\n\n" . file_get_contents($path);<br />
}<br />
}</code></p>
<p>And finally just change your urls to css/packed/prepend/yourcss.css (if you are using relative paths in your css you might need to add an ../)</p>
<h4>Conclusion</h4>
<p>Using this technique your css will load without any problems in third party sites. This comes in very useful when creating widgets or greasemonkey scripts.</p>



Share and Enjoy:


	<a rel="nofollow" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.mellowmorning.com%2F2007%2F10%2F29%2Fusing-php-to-dynamically-generate-conflict-free-css%2F&amp;title=Using%20php%20to%20dynamically%20generate%20conflict%20free%20css" title="Digg"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://sphinn.com/submit.php?url=http%3A%2F%2Fwww.mellowmorning.com%2F2007%2F10%2F29%2Fusing-php-to-dynamically-generate-conflict-free-css%2F&amp;title=Using%20php%20to%20dynamically%20generate%20conflict%20free%20css" title="Sphinn"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/sphinn.gif" title="Sphinn" alt="Sphinn" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://del.icio.us/post?url=http%3A%2F%2Fwww.mellowmorning.com%2F2007%2F10%2F29%2Fusing-php-to-dynamically-generate-conflict-free-css%2F&amp;title=Using%20php%20to%20dynamically%20generate%20conflict%20free%20css" title="del.icio.us"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.mellowmorning.com%2F2007%2F10%2F29%2Fusing-php-to-dynamically-generate-conflict-free-css%2F&amp;t=Using%20php%20to%20dynamically%20generate%20conflict%20free%20css" title="Facebook"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://www.mixx.com/submit?page_url=http%3A%2F%2Fwww.mellowmorning.com%2F2007%2F10%2F29%2Fusing-php-to-dynamically-generate-conflict-free-css%2F&amp;title=Using%20php%20to%20dynamically%20generate%20conflict%20free%20css" title="Mixx"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/mixx.png" title="Mixx" alt="Mixx" class="sociable-hovers" /></a>
	<a rel="nofollow" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fwww.mellowmorning.com%2F2007%2F10%2F29%2Fusing-php-to-dynamically-generate-conflict-free-css%2F&amp;title=Using%20php%20to%20dynamically%20generate%20conflict%20free%20css" title="Google"><img src="http://www.mellowmorning.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google" alt="Google" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.mellowmorning.com/2007/10/29/using-php-to-dynamically-generate-conflict-free-css/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

