You are hereViews help

Views help


MySql alter table Collation - Views is not sorting national characters sollution

I recently had a problem with sorting of chars. I have some Eastern Europe chars. like čćžšđ and they didnt sort like I would like to in views. "Đ" would come at the end of the list after "Z" and it should be after "D" so I found the solution and the problem.

Problem is collation of tables in mysql database and solution is changing it. They were all set to "utf8_general_ci" so I just change node table "node" because I was sorting by title and I did this.

alter table node convert to character set utf8 collate utf8_unicode_ci

Views Arguments validation "Gotcha"

People usually set argument and often don't mind about validation. Just leave basic validation thinking most will pass. But that is not the case. For example you can use User ID ad argument and think both UID and User Name would pass, but that is not the case. You have to go and select "User" Validator and use "Allow both numeric UIDs and string usernames" for this to work. Otherwise you could have a view that is showing nothing and left you wondering what is happening.

Theming filters in Views 2.x differently

Most will use views 3.x in future and they should as they are really better, from UI point of view to other parts but for some old sites that are not updated and you want to theme exposed filters differently, you can't from default. You need to change some template as all your filters have the same classes.

Override the exposed form template in your theme -- take a look at /modules/views/theme/views-exposed-form.tpl.php

Change line 25 from <div class="views-exposed-widget">
to

Drupal Calc and age of users

I am bulding a view with stats for users that are registred and inputed DOB. Currently core profile module and views (drupal 6) don't play along when using dates. The way data is stored seems to be the problem. Anyway you can't filter and sort your users by date, but you can make this happen with customfield PHP code. You get current year and DOB year from user like this and just calculate and you will get age of user, which you can then sort with table view if it is in customfield.

$datum=unserialize($data->profile_values_profile_rodjenje_value);

Custom field in views, dates ande serializing

When using views, sometimes you just can't get output you want for the fields you are outputing, then you use Custom field module. Custom field let's you use PHP as field and get all the date from other field with $data array (output it with print_r ($data); to see what is in there) So i wanted to output date field with a condition. Since profile module and its date field doesn't let you enter blank date you have to display something, a 1.1.1900 would be displayed if nothing is entered. To fix this you make a custom field where nothing is outputed if this date is entered.

Custom imagecache output of image

You are looping through some arrays and you have some image variable, path of original image. You want to print out some variation of that image, this is what you do

print theme('imagecache', 'User_profile', $viewPred[0]->users_picture, $alt, $title, $attributes);

User_profile is imagecache variation and after that is variable where path of our original image is stored. I got that variable from a drupal view but you could get it in some block, or page file or wherever.

Block output and Views output in theme with module_invoke

Every now and then i need to make some custom output of a block, either in some page.tpl.php file or in a drupa interface custom block, either way you can get it with module_invoke function

$block = module_invoke('nice_menus', 'block', 'view', 1); print $block['content'];

Viewfield

Building a node with viewfield cck and need some setup tips? Viewfield provides great setup options, you can set default values and also send any token value to it %nid, %tid etc. But sometimes you will need to make some extra code for passing arguments.

Viewfield, reference views and view reference

Viewfield or reference views. Which to use? Well viewfield is a module where you add CCK filed and you can choose which view you want to have for this field to show. This can be default or can be overridden on node edit form. You can also pass arguments by default or change it on node edit. Reference views is just to change how node reference would look, so basicaly you change display fields.

Taxonomy node module - Term View problem

If you are using Taxonomy Node to have additiona data for your taxonomy you are in for supprise if you go to term page and see "There are currently no posts in this category." message. Other then this, module works fine. To solve this problem, use views and activate default taxonomy_term view and make some eddits.