Posted by Kutakizukari on December 25, 2012 at 1:39am
For Drupal 7 how do I get this stylesheet to only load for the page front-anonymous? https://gist.github.com/4371278
<?php
function v5tfusion_preprocess_html(&$variables) {
drupal_add_css('/css/front-anonymous.css', array('type' => 'external'));
}
?>
Comments
Would this work?
Looking at the api a little I came up with this:
<?php
if ($base_url . '/front-anonymous') {
drupal_add_css(drupal_get_path('theme', 'v5tfusion') . '/css/front-anonymous.css', array('group' => CSS_THEME, 'type' => 'file', 'every_page' => FALSE));
}
?>
If I put this code in template.php, the stylesheet front-anonymous.css should only load when viewing the page at http://example.com/front-anonymous?
Another way to do an if
Another way to do it, using a normal if statement to check your arg(0) or arg(1), depends on how your paths are structured, if front-anonymous is actually a node then you need to check if arg(0) == 'node' && arg(1) == , if its a page, arg(0) == 'front-anonymous' would be enough.
Read more about the arg function
-----------------
http://worchestra.com
So this is also vaild?
@Valor
So this:
<?php
if (arg(0) == 'front-anonymous' {
drupal_add_css(drupal_get_path('theme', 'v5tfusion') . '/css/front-anonymous.css', array('group' => CSS_THEME, 'type' => 'file', 'every_page' => FALSE));
}
?>
Is also valid?
When I tried: <?phpif
When I tried:
<?php
if ($base_url . '/front-anonymous') {
drupal_add_css(drupal_get_path('theme', 'v5tfusion') . '/css/front-anonymous.css', array('group' => CSS_THEME, 'type' => 'file', 'every_page' => FALSE));
}
?>
It returned:
When I tried:
<?php
if (arg(0) == 'front-anonymous' {
drupal_add_css(drupal_get_path('theme', 'v5tfusion') . '/css/front-anonymous.css', array('group' => CSS_THEME, 'type' => 'file', 'every_page' => FALSE));
}
?>
All I got was a blank page after flushing the cache.
I do have the php closing tag ?> removed from the template.php file.
Any help of what to try or where I'm going wrong?
You are missing the closing )
You are missing the closing ) in the if statement
<?phpif (arg(0) == 'front-anonymous') {
drupal_add_css(drupal_get_path('theme', 'v5tfusion') . '/css/front-anonymous.css', array('group' => CSS_THEME, 'type' => 'file', 'every_page' => FALSE));
}
?>
Where in template.php are you placing this? Inside which function?
-----------------
http://worchestra.com
Ah, I assumed the closing )
Ah, I assumed the closing ) tag got auto typed in my editor. Will retry later on today.
Just placing it as is the way you see it within template.php. Is that wrong to do?
<?phpif (arg(0) == 'front-anonymous') {
drupal_add_css(drupal_get_path('theme', 'v5tfusion') . '/css/front-anonymous.css', array('group' => CSS_THEME, 'type' => 'file', 'every_page' => FALSE));
}
Make sure your if statement
Make sure your if statement is inside template_preprocess_html function
<?phpfunction mytheme_preprocess_html(&$variables) {
if (arg(0) == 'front-anonymous') {
drupal_add_css(drupal_get_path('theme', 'v5tfusion') . '/css/front-anonymous.css', array('group' => CSS_THEME, 'type' => 'file', 'every_page' => FALSE));
}
}
?>
-----------------
http://worchestra.com