3

I am trying to change output of some of the fields used inside my panelizer content, i.e node pages, but hook_preprocess_page( &$vars) is showing the output as rendered #markup and i just cant get hold of the render-able array for my content?any help please?

4

There is a template_preprocess_panels_pane

/**
 * Implements preprocess_panels_pane().
 */
function YOURTHEME_preprocess_panels_pane(&$vars) {
}

Documentation

If you want to change the output of a field you have:

/**
 * Implements hook_panels_pane_content_alter().
 */
 function YOUR_MODULE_panels_pane_content_alter($content, $pane, $args, $contexts) {
  $content ...
}
2
  • Thanks a lot for your reply...but for some reason, i did try these hooks,but the values get changed and shows up in dsm() function of the devel module but the output will still be the same....is there going to be some saving inside the function somewhere which will save the display or what?i am sure something is missing that the values dont change in output.... Apr 11 '14 at 6:28
  • YOUR_MODULE_panels_pane_content_alter worked for me, though I initially mistakenly assumed it was a theme hook. Apparently the all caps YOUR_MODULE in the example wasnt enough for me :). Anyways, changing the value of $content->content worked for me. Quick warning for the unwary: That variable can be straight text or a render array, check first to avoid potential type mismatches. Oct 13 '17 at 19:16
1

I know it is an old question but anyone still looking for answer for this, here goes. Looking at function template_preprocess_panels_pane in panels.module file:

$vars['content'] = !empty($content->content) ? $content->content : '';

$content is not an object anymore.

I saw a nice solution here. According to this all you have to do is use hook_theme and set override preprocess functions to true. This way you can copy paste the original function and use it as a way to override. Let me know if you need any more help in this.

0

I can confirm that hook_panels_pane_content_alter() works with Panelizer fields (that could not be modified with hook_node_view or hook_ctools_render_alter).

You use $contexts to determine the content type and raw field values and modify $content to modify the rendered output e.g. here I modify the formatting of a rendered price with the currency module API taking the 3-letter currency code from a different custom field.

/**
 * Implements hook_panels_pane_content_alter().
 */
 function custom_example_panels_pane_content_alter($content, $pane, $args,  $contexts) {
     if(isset($contexts['panelizer']->data->type) && $contexts['panelizer']->data->type = "your_content_type") {
         if ($content->subtype == 'node:field_your_content_type_price' && isset($content->content[0]['#markup']) && isset($contexts['panelizer']->data->field_roomshare_price['und'][0]['value']) && is_numeric($contexts['panelizer']->data->field_your_content_type_price['und'][0]['value']) && isset($contexts['panelizer']->data->field_your_content_type_currency_type['und'][0]['value']) && strlen($contexts['panelizer']->data->field_your_content_type_currency_type['und'][0]['value']) == 3) {
            $currency = currency_load($contexts['panelizer']->data->field_roomshare_currency_type['und'][0]['value']);
            if ($currency) {
                $amount = $contexts['panelizer']->data->field_your_content_type_price['und'][0]['value'];
                $formatted = $currency->format($amount);

                $content->content[0]['#markup'] = $formatted;
            }
            }
    }
}

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.