selfsimilar
selfsimilar

Reputation: 1387

Can I preprocess a Less css file?

I'm using Less with Drupal, and I want to allow admin users to define colors for certain site elements globally. To clarify, we have a certain type of content, call it a "level" and admins can add a level to the site. Each level should have an associated color which will be the border color for certain divs, etc. I'd like the admins to be able to set the color through the cms and have that reflected in an external style sheet.

All the affected elements in the DOM are indexed by class. The only thing I can think of is in the main Less file to import a second Less or CSS file that would be generated dynamically by Drupal. I just want to make sure there's nothing I'm missing, for example a way to inline php in a less file and have the php executed before it's passed off to the browser or server-side less compiler.

Upvotes: 1

Views: 332

Answers (1)

bzx
bzx

Reputation: 1364

With this approach you're going to end up with hundreds (or whatever your audience is) of generated .less files. Not sure if it's the approach you wanna take.

Let users define colors and store that in db, then when user logs in, load his settings and generate CSS code which you simply embed in the header.php (or similar file that gets loaded on every page in Drupal):

<?php if ($user->logged_in) { ?>
<style type="text/css">
  .header {
    background-color: <?php echo $background-color; ?>;
    color:            <?php echo $header-color; ?>;
  }
  .content {
    ...
  }
  ...
</style>
<?php } ?>

.. and the rest of your styles is defined in LESS files.

Default user (not logged in) will get default colors for these elements, that you define in your LESS files. The above will simply overwrite them (so make sure you embed it below you call the main stylesheet).

I'd do that this way.

Upvotes: 0

Related Questions