I have a preprocess function:
[MYTHEMENAME]_theme_preprocess_views_view_fields__random_quote__block(&$vars)
and then a template file to render the variables:
views-view--random_quote--block.tpl.php
I can easily set a variable like so:
$vars['bam'] = 'whatever';
and display that in my template file. Now my question is, how do I pass the contents of a field to my template? Something like:
$vars['customer_name'] = 'field_customer_name';
Where 'field_customer_name' is a field in the content type. I have tried using the field api and I am getting nowhere. My view is getting that field and I can see the data in the preview of the view content
I still haven't figure out how to do this, but I ended up using a fields tpl (in this case: views-view-fields--random_quote.tpl.php) so I could format each field like so
<cite><b><?php print strip_tags($fields['field_customer_name']->content); ?></b>
Ok, I figured out how to do it!
$entity = $vars['view']->result[0]->_field_data['nid']['entity'];
$vars['customer_name'] = '$entity->field_customer_name[$entity->language][0]['value'];
Hope this helps someone
Related
I'm trying to print the full name of user instead of the username using theme('username',$name); The full name is displayed but with as a hyperlink (in between <a>..</a>) which links to the user's profile page. I just want theme() to output the full name as plain text. Can anyone help?
Please could you say from where you are trying to print the username.
If you are doing this in the template.php, you can get it say from node_preprocess or page_preprocess using:
print $vars['user']->name;
Or if you are in a .tpl file you can use
<?php print $user->name; ?>
User is a global variable so you can grab all kinds of information from it.
If you want to see the available information try putting this in the template.php, say in page_preprocess function / (hook)
print_r ($vars['user']);
i am a newby to drupal.
here is my problem:
on my main page.tpl.php i have this code lines:
"if ( $is_front == TRUE ) {
print views_embed_view('all_product_by_type_thin', "default", "canon");
print views_embed_view('all_product_by_type_thin', "default", "Nikon");
}"
as you can see, in case of the front page i print the "all_product_by_type_thin" view while sending parameter "cannon" and "nikon"
the result of the all_product_by_type_thin view is altered inside the views-view-unformatted--all_product_by_type_thin.tpl.php file.
in that file i am wrapping the view results in all kind of divs.
what i need to do though, and cant figure out a way to do it, is get the argument i sent the view "canon" or "nikon" inside the php code of views-view-unformatted--all_product_by_type_thin.tpl.php
any idea ?
Inside your Views theme file ie. views-view-unformatted--all_product_by_type_thin.tpl.php you should have access to the $view object.
One of the attributes of this object will contain the arguments passed to the view. You can do a print_r and find this attribute and hence, the arguments.
I have a Drupal filter module whose output I would like to alter, depending on where the output is going to be displayed. Specifically, I want to the filter to give the full output for nodes, but trim the content down for blocks.
I don't think this would be possible. It's hard enough to figure out what context something is being displayed in. It's doable but quite hard to code on your own. However the way the filter system works I don't think its possible within a filter to determine then context of the text being filtered. It's simply not made for something like that.
I'm the OP (but just registered an account).
I did manage to find a solution/workaround. Here's what I did:
Create block.tpl.php in my module which is a copy from system/block.tpl.php, with a constant added at the top.
Put my template file at the head of the theme registry using hook_theme_registry_alter():
function hook_theme_registry_alter(&$theme_registry) {
// using our own block.tpl.php file.
$theme_registry['block']['template'] = 'block';
$theme_registry['block']['path'] = drupal_get_path('module', 'module_name');
$theme_registry['block']['type'] = 'module';
$theme_registry['block']['theme path'] = drupal_get_path('module', 'module_name');
$theme_registry['block']['theme paths'] = Array();
}
Checked for the constant while constructing the filter output, changing as necessary.
Celebrated the outcome.
I'm a drupal newbie...
<?php print $node->field_date[0]['view']; ?>
I can get the custom created CCK fields' value and display in tpl.php files as above... that's fine.
my question is how can I get the Node reference fields' in-fields? for example, I have an event content type, and I have defined Node Reference for Location (title, address, img, etc.). When I write the code below, it displays all location content;
<?php print $node->field_location[0]['view']; ?>
but I need to get only address field from this location content type. sth like below would be great :D but not working;
<?php print $node->field_location[0]['field_address']['view']; ?>
so how can get that? appreciate helps so much! thanks a lot!
You should inspect/dump the content of the $node->field_location array. I do not have a test installation at hand right now, so I can't say for sure, but I'd expect that at least the referenced nodes id ('nid') should be in that array somewhere. With that, you can do a node_load($nid), which returns the full node object, thus providing access to the fields.
(As said, I'm not sure, but the field array might already contain the whole node object as well, saving you from the need to load it explicitely.)
The $node->field_location[0]['view']; returns the node as it was defined in the Display Fields section of the content type definition. This might work for your advantage. You can trick it: use a Teaser display for that node and customize the node Teaser display to fit your needs. Just a thought.
If that doesn’t work for you, you will need to load the node separately. You can use $node->field_location[0]['nid']; to get the node ID, so you will end up with something like this:
node_load($node->field_location[0]['nid'])->field_address[0]['view']
I'm not sure how this performs...
I'm trying to create an img link manually with php in the header field of a view, in drupal 6. I need to read the value of one of the filters, but can't find the right variable to read. I thought I could print_r($view->filters) but it didn't give me anything, and I eventually found out that isset($view) is false.
Am I looking the wrong way?
The context I'm writing in is the header field of the view, with php code as input format. Do I have to "enable" the $view variable for reading in this context somehow?
OK I found it, it was really easy:
$pa_view = views_get_current_view();
$pa_nr = $pa_view->display['default']->display_options['filters']['field_nummer_value']['value']['value'];