2

I've got a block created with views, which displaying a slider. The slider is created as an unpublished content type with two field collections:

Settings[one value]:

  • selectors type: thumbs or bullets
  • slider class: fixed position, faded etc.



Slider content[multiple values]:

  • slide class
  • content class
  • Image
  • content

I do not use views slideshow module
I'm using views-view--slider-block.tpl.php file to customize the output

All works, but I have stuck with one specific setting "fixed position" - this setting should add to html a special class, which I guess can be added only by preprocess_html function:

function MYTHEME_preprocess_html(&$variables) { 
    if ( SLIDER HAS "fixed" SETTING ){
        $variables['classes_array'][] = 'slider_fixed';
    }
}

the problem is:

  1. how to compose the if statement?
  2. Did I have to load $view object which allows me to check what setting is used?

I'm looking for the solution which has the lowest influence on the performance.

any suggestions?

  • If you can add this class to the html of the block in use instead of the page body, you should be able to access the Views object as $view in your Views template. – Jimajamma Apr 28 '13 at 17:09
  • Yes, I have a variable with the setting in views template file. The problem is how to pass it to MYTHEME_preprocess_html() – Jack-PL Apr 28 '13 at 17:10
  • right, but can the slider js you have use a class in its wrapping block's div instead of looking at the page's body/html tag? – Jimajamma Apr 28 '13 at 17:13
  • this class has to be in body to achieve the effect (fixed position of the slider towards to body) – Jack-PL Apr 28 '13 at 17:17
  • gotcha. grr. there really isn't any direct way to do what you want to do then. – Jimajamma Apr 28 '13 at 17:27
3

The Context API allow to pass a variable from view.tpl to template.php file

Example:

In view.tpl file :

context_set('slider_settings', 'slider_class', 'fixed_position');

In theme template file :

function MYTHEME_preprocess_html(&$variables) {

$slider_class = context_get('slider_settings', 'slider_class');
if ($slider_class == 'fixed_position'){
    $variables['classes_array'][] = 'slider_fixed';
}

}

It is an aswer for my own question, because I found a solution by myself, and it might be useful for someone I think..

  • This is excellent, using it on a current project, thanks. – Danny Englander Apr 17 '14 at 21:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.