View Template Override that is full page - drupal

I need to create a template for a view i've created (which I know how to do) but I don't want the page to be wrapped in the drupal html.php code. I want the resulting page to be only what is in the template file I create.
How do I do this?
I did found this which does what I need for content types lab
function yourthemename_preprocess_html(&$vars) {
if ($node = menu_get_object()) {
if($node->type == "lab") {
$vars['theme_hook_suggestions'][] = 'html__lab';
}
}
}
Then created a file called: html--lab.tpl.php
Can this method be used for my view?
does it have to be if($node->type == "lab")?
can I use something like if($view == "viewname")
Thanks
C

I think when you says "created a view" you mean a view + a page display.
So, when you browse to http://mystite.com/mypage, it will show the content of view.
In this case, you can use your code with some small modifications.
function yourthemename_preprocess_html(&$vars) {
if (arg(0) == 'mypage') {
$vars['theme_hook_suggestions'][] = 'html__mypage';
}
}
You will have to create the right .tpl.php file and clear the cache.

Related

Adding space to select option in form alter

I have taxonomy terms hierarchy and I am using them as a filter in a view. It is showing hierarchy in the selectbox, but child terms appearing with hyphen(-). I have tried to drop hyphen in form alter, and I did, but I couldn't replace it blank space.
if ($form_id == 'views_exposed_form') {
$i = 0;
foreach ($form['field_region_tid']["#options"] as $op) {
foreach ($op->option as $key => $arr) {
if ($arr != null) {
$form['field_region_tid']["#options"][$i]->option[$key] = str_replace("-"," ", $arr);
}
}
$i++;
}
}
How can I put blank space at the beginning of the child options. Or should I do some other way?
Thanks!
From the form_id I get that it is a form generated by views. If so, the code inside the if condition never gets called because your module is executed after the views module due to the weight of both modules. To fix that:
Open your database manager (PhpMyAdmin in most cases) and open system table.
Then change the weight for your module to something larger than 10, because it is the default weight for the views module and you need you module to be executed after the views module.
Hope this helps... Muhammad.
if the problem is when your hook is called the answer lies in
hook_module_implements_alter()
but it is not as you say. Your code looks fine,
Have you tried
str_replace("-"," ", $arr);
?

Add class to an image field for a specific content type in Drupal 7

Currently I'm using the code as suggested in this answer. Which is the following:
function simalr_preprocess_image(&$variables) {
if ($variables['style_name'] == 'request-background') {
$variables['attributes']['class'][] = 'pixastic';
$variables['attributes']['class'][] = 'pixastic-blurfast(amount=1)';
}
}
This works fine except for the fact that I get the following error message on a page which doesn't have an Image with the 'request-background' style:
Notice: Undefined index: style_name in simalr_preprocess_image() (line 46 of /var/www/vhosts/simalr.com/httpdocs/sites/all/themes/simalr/template.php).
I only want this piece of code used on a specific content type (namely 'request'). In which way do I have to adjust the code in my template.php file in order to just use it on a page which is only of a certain content type?
You can still work with your code but use isset function. This will remove the warning.
If you want to do it just for a specific content type use menu_get_object function in drupal. This function will return the node for you if it's a node page.
Example:
$node = menu_get_object();
if ($node->type == 'story') {
// TODO
}
Hope this helps.

Drupal 7 theme_hook_suggestions not working

How do I add 2 for one view display override?
This is the code I have that works:
function yourthemename_preprocess_html(&$vars) {
if (arg(0) == 'qrule') {
$vars['theme_hook_suggestions'][] = 'html__qrule';
}
}
HTML template page called: html--qrule.tpl.php
This works fine! (thanks #Ionut.A)
But I also want to override the page.tpl.php too with page--qrule.tpl.php but when I add this:
function mythemename_preprocess_html(&$vars) {
if (arg(0) == 'qrule') {
$vars['theme_hook_suggestions'][] = 'html__qrule';
$vars['theme_hook_suggestions'][] = 'page__qrule';
}
}
PAGE template page called: page--qrule.tpl.php
I get this error:
Fatal error: Only variables can be passed by reference in /var/www/vhosts/xxx/public_html/sites/all/themes/themename/page--qrule.tpl.php on line 1
Can anyone see what i'm doing wrong here?
Thanks
C
If you're adding a theme hook suggestion for the page.tpl.php file you'll need to to it in hook_preprocess_page():
function mythemename_preprocess_page(&$vars) {
$vars['theme_hook_suggestions'][] = 'page__qrule';
}

Get $node variable in html.tpl.php - Drupal 7

I'm trying to allow users to update head titles and meta descriptions for each page. I thought that an easy way to achieve this would be to add a field to the 'Basic page' content type for the page title, then check if that field is not empty in html.tpl.php and if it is not, override $head_title with this user-defined value.
However, it appears that the $node variable is not available in html.tpl.php. Can anyone suggest a way for me to make this data available in this template file, or alternatively, alter $head_title before it is sent to html.tpl.php? Thanks for reading.
Taken in part from this thread that I found: http://drupal.org/node/1041768...
In your template.php, you can do the following:
function yourtheme_preprocess_html(&$variables) {
// If on an individual node page, add the node type to body classes.
if ($node = menu_get_object()) {
$variables['head_title'] = $node-> // find your cck field here
}
}
Bit messy, but would work:
if(arg(0) == 'node' && !empty(arg(1))) {
$node = node_load(arg(1));
}
However, you might prefer http://drupal.org/project/metatags_quick (an interrim module until the full http://drupal.org/project/metatags is finished).

Determine if the current Drupal page is a search results page?

How can I determine if the current Drupal page is a search results page?
Assuming clean URLs are on, this usually works
function MYTHEME_preprocess_page (&$vars, $hook) {
// ...
if ($hook == 'page' && arg(0) == 'search') {
// do search related stuff
}
}
inside your template.php.
Normal template suggestions work, too, such as using a page-search.tpl.php instead of page.tpl.php if that is also needed.

Resources