Programmatically adding field in VIEWS

Public
</> CopyGet raw version
php
  1. // Add 'Custom text' field
  2. function hook_views_pre_view(&$view, &$display_id, &$args) {
  3. if ($view->name == 'my_view') {
  4. $view->add_item($view->current_display, 'field', 'views', 'nothing', array(
  5. 'label' => 'My field',
  6. 'alter' => array('text' => 'My field text'),
  7. 'element_class' => 'my-field',
  8. 'element_default_classes' => 0,
  9. ), 'my_field');
  10. }
  11. }

Comments

Rajesh's picture

How can I pass html with text. Like 'alter' => array('text' => 'My field text'),