Latest News:
Latest Mods: Latest Tutorials:


 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Customization Tutorial Adding LESS CSS support to MyBB
Author Message
euantor
Posting Freak



Posts: 881
Joined: Jun 2009
Reputation: 7
Post: #1
Adding LESS CSS support to MyBB
This tutorial will show you how to add support for LESS CSS to the MyBB. For this tutorial, we will be making edits to a core file. You can either do this manually or via the Patches plugin. Personally, I prefer the latter (just because it makes life easier once you have a few core edits in place) though i's up to eprsonal preference. For those wanting to use the patches plugin, simply download the patches file below and import it (NOTE: if you have a different name than /admin/ for your admin directory, you'll have to change the patch slightly to point to your admin directory).

No matter what method you're using though, you'll need to download the attached lessc.inc.php file and upload it to you /admin/inc/ directory.


Ok, so now to actually make the change. Open the /admin/inc/functions_themes.php file using your editor of choice (notepad++ for myself). Find the following line of code:

PHP Code:
    $stylesheet parse_theme_variables($stylesheet$theme_vars); 

Before this line, add the following:

PHP Code:
    require_once 'lessc.inc.php';
    
$less = new lessc();
    
$stylesheet $less->parse($stylesheet); 

Simple. That's all there is to it! Now, time to test if your new edit works. head to the styles and templates area of the ACP and open up a theme's CSS file. Scroll down to the bottom of the file and add the following code:

PHP Code:
@base24px;
@
border-color#B2B;

.underline border-bottom1px solid green }

#header {
  
colorblack;
  
border1px solid @border-color #222222;

  
.navigation {
    
font-size: @base 2;
    
{
    .
underline;
    }
  }
  .
logo {
    
width300px;
    :
hover text-decorationnone }
  }


Save the CSS file and when you scroll back down to where you inserted the new LESS, there should be some translated CSS content that looks like this:

PHP Code:
.underline border-bottom:1px solid green; }
#header {
  
color:black;
  
border:1px solid #dd44dd;
}
#header .navigation { font-size:12px; }
#header .navigation a { border-bottom:1px solid green; }
#header .logo { width:300px; }
#header .logo:hover { text-decoration:none; } 



Sorted. You can now write LESS right into your stylesheets. The only problem is in the way that the MyBB cache works. My original plan was to store pure LESS in the database, then convert it to CSS only within the cache file. However, MyBB watches fo changes to the cache file and updates the database style with that of the cache content. No matter - the outcome works as intended to an extent (though theme authors can't distribute LESS powered themes - which would have been cool). We could always go the whole way and basically rewrite a ton of the cache and get what we want, but things work as is, so let's leave it at that for now.

NOTE: If you don't fancy editing core files in any way, you can always use the LESS.js translator - though it slows down client-side page rendering slightly and I haven't tested if it'll work with mybb (as you'd have to rename .css files to .less...). If that doesn't matter to you though, I'd go for it - that way you can keep your LESS saved for easy editing



DOWNLOAD
04-27-2011, 11:07 PM
TeraByTe
PHP Coder


Posts: 65
Joined: Mar 2011
Reputation: 1
Post: #2
RE: Adding LESS CSS support to MyBB
thanks ... Works fine 8-)

[]Hallway Insider Forums - Join Now. [/]
Goals :
✔ = Complete X = Incomplete
[✔] 1 Rep
[X] 5 Rep
[✔] 50 posts
[X] 100 Posts
04-28-2011, 06:48 AM
zZJoennZz
Member


Posts: 92
Joined: Oct 2010
Reputation: 0
Post: #3
RE: Adding LESS CSS support to MyBB
Wow! LESS CSS is very good project!
04-28-2011, 08:18 AM
euantor
Posting Freak



Posts: 881
Joined: Jun 2009
Reputation: 7
Post: #4
RE: Adding LESS CSS support to MyBB
Thanks guys. Yes, LESS is great. I've been using it with wordpress for a while now.
04-28-2011, 10:41 AM
w-miky-w
Junior Member


Posts: 42
Joined: Nov 2010
Reputation: 0
Post: #5
RE: Adding LESS CSS support to MyBB
:O it works it very well !!!
05-03-2011, 09:23 PM
davidedison
Member


Posts: 65
Joined: Jul 2010
Reputation: 0
Post: #6
RE: Adding LESS CSS support to MyBB
Thanks!
05-19-2011, 09:04 PM
ProVirus
Junior Member


Posts: 7
Joined: Mar 2010
Reputation: 0
Post: #7
RE: Adding LESS CSS support to MyBB
Well, optimization is always good
07-09-2011, 08:39 PM
 




User(s) browsing this thread: 2 Guest(s)