how do I use it?

roundboy - June 30, 2007 - 23:01
Project:Component
Version:6.x-1.x-dev
Component:Documentation
Category:support request
Priority:normal
Assigned:Unassigned
Status:active
Description

how do I use it? I can't find any manual for it.

#1

stinky - July 19, 2007 - 20:44

Ditto. how do I use it?

#2

yngens - September 24, 2007 - 22:31

same question here.

readme file is very laconic. no settings or detailed instruction for the module.

#3

Crell - November 8, 2007 - 19:28

It's a utility module, mostly for themers. See: http://www.garfieldtech.com/blog/component-module

#4

pcdonohue - December 12, 2007 - 15:22

The component module provides hooks that you can call via urls to access your sites data via an AJAX call.

For example, for views, you can load http://yoursite.com/component/view/yourview and it would return your view...

I still haven't quite figured it all out but here's an example from the site I'm developing.

I have a view named bopedia that I want to display at the bottom of a page. The usability I want is to be able to page through that view without having to reload the whole page (clicking on the pager would normally reload the entire page).

I set up a div with an id and a url variable that I can use to pass which view I want to page through, and then use views_build_view to embed the view in the page for the first time.

<div id = "moreview" url = "/component/view/bopedia" >
<h2>Browse the BoPedia</h2>
<div id = "viewwindow" >
<?php
$view_name
= 'bopedia'; //name of view
$view_args = array();
$view = views_get_view($view_name);
$view->url = 'bopedia';
print
views_build_view('embed', $view, $view_args, $view->use_pager, $view->nodes_per_page);
?>

</div>
</div>

Then I have some jquery code set up to catch clicks on the pager items, with a few helper functions too.

jQuery.fn.pageNumber=function() {
var pageText = this.attr('href');
var i = pageText.lastIndexOf('?page=');

if (i < 0) {
return 0;
} else {
return parseInt(pageText.slice(i + 6));
}
};

jQuery.fn.ajaxPager=function() {
var pageNo = $(this).pageNumber();
var url = $('#moreview').attr('url');

if (pageNo > 0) {
url = url + '?page=' + pageNo;
}

//fade out old elements
$('#viewwindow .view-content .view-grid-item .view-item').fadeTo(500, .0);

// issue an ajax call to the component module via the provided url
$.get(url, null, function(data) {
//replace the view with the data returned from the call
$('#moreview #viewwindow').html(data);
});
}


// register the page events
if (Drupal.jsEnabled) {
// logo hover effect
$(document).ready(function() {   

//pager for page bottom browsing functions
$('#moreview').click(function(event) {
   if ($(event.target).is('.pager a')) {
$(event.target).ajaxPager();
return false;
   }
});


});
}

This works, when I click on the pager it fades out the current items and then loads the new ones. Though with one problem mentioned at http://drupal.org/node/197879

I'm also certain this could be a lot cleaner too.

#5

FatalRemedy - December 23, 2007 - 01:27

I didn't find that the site said much about it.
If you simply look inside the component.module you can see the various functions it provides, I've taken most of them out, just to make it a bit easier.

All of these are functions that can be called like <? echo component_get_view('articles_top_rated'); ?>

component_get_block($module, $delta, $title_text = NULL)
- Returns the themed contents of a block specified by module and delta
@param string $module - The module that provides the block we want
@param mixed $delta - The delta of the block we want
@param string $title_text 0 The text to use in place of the default title, if any

component_get_view($view_name)
- Output function for the 'views' content type. Outputs a views based on the module and delta supplied in the configuration.
@param $view_name - The name of the view to display

component_get_view_filter_form($view_name)
- Returns the rendered filter form for a specified view

component_get_panel($did)
- Returns rendered panel

component_get_node($nid)
- Returns rendered node

#6

kulfi - August 20, 2008 - 04:40

Like the others, looking for documentation ...

#7

leafish_paul - August 20, 2008 - 11:58

See #3 - the module provides several functions for coders/themers to call to grab nodes, blocks, panels views etc. There are no need for settings.

#5 is an outline of the functions available, perhaps these should be added to the project page and/or README.txt

#8

jitj - March 13, 2009 - 17:53
Version:5.x-1.x-dev» 6.x-1.x-dev

I found a neat use for this module in order to put content from a view provided block into a block on another site. Just install and activate this module on the site providing the information and then put the following php snippet into your block on the site where you want the information to display:

<?php print file_get_contents('http://www.example.com/component/block/views/name_of_block-block_1'); ?>

This is much more elegant than trying to use iFrame. I'm using it for a multi-site setup where I want an alert box showing on all of the sites.

#9

bloke_zero - June 16, 2009 - 16:25

you can get the basic node e.g.

node/955/component

without header and footer - great for little pop-ups with thickbox

 
 

Drupal is a registered trademark of Dries Buytaert.