Preprocess functions

Your Ad Here

A Views Slideshow: Dynamic Display Block uses two preprocess functions to convert view fields into template variables. One for the whole slideshow template and one for the pager template.

Important to understand about field data from views used in the preprocess functions.

  • The data used from the view for fields is "RAW" data, settings in views like trimming etc. are not used in the data for the field.
  • When you want e.g., trim data in a field you need to add the code yourself in the preprocess function.
  • An example of code used from trimming a field can be found at: http://drupal.org/node/582520 #21
  • In version 2 of the views_slideshow_ddblock module, rendered data from the view is used, and all views functionality is available.
  • Install preprocess functions

    • The preprocess functions have to be placed in the template.php file of your theme.
    • Copy the preprocess function code from the template.php.txt file to the template.php file. The template.php.txt file is part of the vsd_export_files-Vx-x.zip. package
    • Replace [***THEME_NAME***], including the brackets, with the name of your overall site theme name you use, in both preprocess functions.
    • Change the view_name in both preprocess functions if your view has another name than: news_items. See Changing view_name and or view_field names below.
    • Change the field_names if you have other fieldnames in your view. See Changing view_name and or view_field names below.

    Note: You can see the view_name and the available field_names by showing the debug info, by setting this in the views ddblock configuration page.

    In the example preprocess function the following variables are now available in the slideshow template for each slide.

    • $slider_items['slide_image']
    • $slider_items['slide_text']
    • $slider_items['slide_title']
    • $slider_items['slide_read_more']
    • $slider_items['slide_node']

    and the following for each custom-pager-item

    • $pager_items['image']
    • $pager_items['text']

    Changing view_name and view_field names
    If you use a different view_name and view fields than the default news_items view and field names, you have to change them in the preprocess functions.

    Show debug info which you can configure at the views ddblock configuration page.

    [***THEME_NAME***]_preprocess_views_slideshow_ddblock and [***THEME_NAME***]_preprocess_views_slideshow_ddblock_pager_content

    You will now see the result of the drupal_set_message lines, which shows the view_name and the view_fields of your view. You can use this for changing the view_name and the view_field names in the preprocess functions in the template.php file.

    Changing view_name
    In the line:

    if ($settings['view_name'] == 'news_items') {

    you fill in your own viewname

    if ($settings['view_name'] == '[VIEW_NAME]') {

    Changing view_field_names
    In the lines like:

     
    if (isset($result->node_data_field_pager_item_text_field_slide_text_value)) {
      $slider_items[$key1]['slide_text'] =  check_markup($result->node_data_field_pager_item_text_field_slide_text_value);
    }

    You fill in your own view_field_names

    if (isset($result->[VIEW_FIELD_NAME])) {
      $slider_items[$key1]['slide_text'] =  check_markup($result->[VIEW_FIELD_NAME]);
    }

    Note:
    After you have changed the view_name and view_field go back to your views ddblock configuration page and set, Show debug info to <none> again.

    Comments

    HI, what do you mean ddblock

    HI, what do you mean ddblock configuration page? and show debug info? where do i find those?

    Re: HI, what do you mean ddblock

    An explanation where to find the configuration page can be found in the Configure News item slideshow views block settings page and Configure ddblock slideshow pages.

    preprocessing problem

    hi
    i followed your informative tutorial and i ve learnt a lot. but when i reached the stage of the last part preprocessing i encountred this problem:
    first i opened the template.php.txt file and changed the name to garland but i was very confused later.
    according to this tutorial i should copy and paste template.php.txt file content to the template.php and upload it to themes/ garland and i overwrote the old template.php but when i refresh i have a posted error msg.
    plz help and explain to me this stage i ve spent more than 4 hours redoing it.
    thanks

    Re: preprocessing problem

    You should copy the content of the template.php.txt file to your existing template.php file of the theme you use for your site.

    Please create an issue in the issue queue of the views_slideshow_ddblock module.

    Attach your template.php file, the result of the debug lines and a link to the slideshow on your Internet site.

    What is the error you get?