0

I am looking for a way to create a view/block that is styled with CSS by myself, that can have content uploaded by an administrator, that will automatically use the same styles.

So it is easy for the admin to add content repeatedly that will automatically through my preconfiguration layout with the CSS as I have styled it.

I thought maybe I could create a content type then run it through a view and place that view on the page that I need it. I this case it is an Image/Icon with a link and text description, so the admin can upload the content easily and it will layout as I have styled it without them needing to write any CSS.

Thanks

Ant:-)

0

Yes I could work with a specific content type and views. an alternative way is to create a module with a specific form to change the content block, and to add the content to the block API.

1 _ add your admin path

function my_module_menu() {
 $items['content_block'] = array(
  'menu_name' => 'main-menu',
  'type' => NORMAL_MENU_ITEM,
  'title' => 'My content block',
  'page callback' => 'drupal_get_form',
  'page arguments' => array('my_module_form'),
  'access arguments' => array('admin_content_block'),
 );
 return $items;
}

2 _ Set your permission

function my_module_permission() {
 return array(
  'admin_content_block' => array(
      'title' => t('Can change content block'),
  ),

}

3 _ A form dedicated to your admin, allowing to change the content :

function my_module_form($form, &$form_state){

$form['block_content'] = array(
   '#type' => 'textarea',
   '#title' => t('Block Content'),
    '#default_value' => variable_get('my_module_block_content', ''),
);
$form['submit'] = array(
      '#type' => 'submit',
      '#value' => t('Submit'),
);

return $form;
}

function my_module_form_submit($form, &$form_state) {
   variable_set('my_module_block_content', $form_state['values']['block_content']);
}

4 _ your block view

function my_module_block_info() {
$blocks['block_content'] = array(
  'info' => t('Block Content'),
);
return $blocks;
}

function my_module_block_view($delta = '') {
if ($delta == 'block_content') {
    $block['subject'] = t('Your block title');
    $block['content'] = variable_get('my_module_block_content', '');

    }
return $block;
 }
  • Can you explain a little bit more about doing it through content and views, do you just create the content type with specific fields then channel it through a view and ouutput through the block? – Ant Power Nov 4 '13 at 22:44
  • It works with content type & views and the way you suggest it is correct. But I think that code that I written (see above) is better (lighter). – bobylapointe Nov 5 '13 at 7:41

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.