[support] Different stylesheet based on path

Cog Rusty cog.rusty at gmail.com
Mon Jun 30 16:37:36 UTC 2008


I was aquainted with that technique in this forum discussion:

http://drupal.org/node/271818

Maybe you could message the guy who finally seemed to succeed in doing that.



On Mon, Jun 30, 2008 at 7:15 PM, Jody Cleveland <cleveland at winnefox.org> wrote:
> I just can't seem to get this to work... I've tried this:
>
> function salamander_preprocess_page(&$variables) {
>  $front_style = path_to_theme() .'/front-page.css';
>  $path_style = path_to_theme() .'/path-'. arg(0) .'.css';
>
>  if (file_exists($front_style) && $variables['is_front']) {
>    $include_style = $front_style;
>  }
>  elseif (file_exists($path_style)) {
>    $include_style = $path_style;
>  }
>
>  if (isset($include_style)) {
>    drupal_add_css($include_style, 'theme', 'all', FALSE);
>    $variables['styles'] = drupal_get_css();
>  }
> }
>
> Cleared the site cache, refreshed pages, and I don't see anything added to
> the header. I'm guessing there should be something like:
> <link type="text/css" rel="stylesheet" media="all"
> href="/sites/beta.menashalibrary.org/themes/salamander/path-xxx.css" />
>
> I also tried this:
>
>  //explode() will split the given string with another string and put the
> pieces into an array
>  $path_pieces = explode('/', drupal_get_path_alias($_GET['q']));
>
>  //so if your path is /abc/def, $path_pieces is now like Array ( [0] => abc
> [1] => def )
>
>  //Therefore, $path_pieces[0] prints 'abc' that you wanted
>  print $path_pieces[0];
>
> And, when I view the source, I don't see anything containing node/xxx
>
> So, I'm really stumped. I am supposed to be adding these to template.php of
> the theme I'm using, right? Basically, I want all page urls that are teens/*
> to use the teens.css file I have in my theme.
>
> - jody
>
>
> On 6/29/08 5:33 PM, "Cog Rusty" <cog.rusty at gmail.com> wrote:
>
>> For Drupal 6, see also this for how to add stylesheets to a theme's .info file
>>
>> http://drupal.org/node/171209
>>
>> and this for a more versatile method for adding path-based stylesheets:
>>
>> http://drupal.org/node/225868
>>
>> Note that arg() always returns the original drupal path (such as
>> node/nn) and not the alias, so in some cased you may need to use
>> drupal_get_path_alias($_GET['q']) and then split it.
>>
>>
>>
>>
>> On Sun, Jun 29, 2008 at 9:15 PM, KOBA | Hans Rossel <info at koba.be> wrote:
>>> I think you will always get "node" for arg(0) when the pages under /teens
>>> are nodes.
>>> So
>>> switch (arg(0)) {
>>>  case 'teens':
>>> will never happen.
>>> It works for admin because those pages are no nodes.
>>>
>>> To get teens when the path alias is /teens you should use
>>> <?php
>>>   //explode() will split the given string with another string and put the
>>> pieces into an array
>>>   $path_pieces = explode('/', drupal_get_path_alias($_GET['q']));
>>>
>>>   //so if your path is /abc/def, $path_pieces is now like Array ( [0] => abc
>>> [1] => def )
>>>
>>>   //Therefore, $path_pieces[0] prints 'abc' that you wanted
>>>   print $path_pieces[0];
>>> ?>
>>> See http://drupal.org/node/227849.
>>>
>>> Good luck!
>>>
>>> Hans
>>> www.koba.be
>>>
>>>>
>>>>
>>>> Still not working for me. I placed this at the top of my theme's
>>>> template.php:
>>>>
>>>> switch (arg(0)) {
>>>>  case 'admin':
>>>>    drupal_add_css(path_to_theme() .'/admin.css', 'theme', 'all');
>>>>    break;
>>>>  case 'teens':
>>>>    drupal_add_css(path_to_theme() .'/teens.css', 'theme', 'all');
>>>>    break;
>>>> }
>>>>
>>>> The url path I'm trying to change the css for is /teens and the css file
>>>> I'm
>>>> trying to use is teens.css. I've tried clearing the cache, but when I view
>>>> the source of the teens page, there's no reference to teens.css.  Is there
>>>> something else I missed? Can I also use this with wildcards? (case
>>>> 'teens/*'
>>>> so that all pages within that area get that theme)
>>>>
>>>> Thank you so much for your time in helping me with this.
>>>>
>>>> - jody
>>>>
>>>> --
>>>> [ Drupal support list | http://lists.drupal.org/ ]
>>>
>>>
>>>
>>>
>>> --
>>> [ Drupal support list | http://lists.drupal.org/ ]
>>>
>
>
> --
> Jody Cleveland
>
> "It's because I take you so seriously that I can't bring myself to believe
> in you."
> - Julia Sweeney ~ Letting Go of God
>
> --
> [ Drupal support list | http://lists.drupal.org/ ]
>


More information about the support mailing list