What should be considered the optimal way of creating a custom field in views?
For example:
if($content_type == 'article'){
print 'something';
}
else{
print 'something else';
}
I either create a Custom Text field and write my php code in its template, or, lately, I've started using views_php field.
The disadvantage with the templates is that if your site is kinda big, you end up with tons of template files that are sometimes hard to manage, and also (obviously) cannot be managed from someone without server access. Furthermore it cannot support sorting/filtering of some kind. Apart from that, it's "fail safe", it's robust, it doesn't add to complexity via an extra module.
The (possible) disadvantage of the php field is that it's an extra layer of complexity to the site and thus an extra bug possibility. Apart from that, it's easily manageable and it can even be used for filtering/sorting!
So, what would you guys suggest? What do you usually do in such cases?
eval()
(which everybody knows is evil and a huge security risk; if you haven't come across that truth before Google it - you'll never use the PHP filter again!) Couple that with the inability to revision code held in the database and there's just no argument for using the PHP filter at all IMHO.$views = db_query("SELECT vv.name, vd.id FROM views_view vv INNER JOIN views_display vd ON vd.vid = vv.vid WHERE display_options LIKE '%php_output%'")->fetchAll();
,$views
will contain a list of rows from the main views table, check thename
column for the view name and go from there