Blogs on

Views

knackforge blog

Drupal Views exposed filter as Links

In Drupal views, we have the option of exposing the filters to users. By default, the exposed filters are displayed as Select boxes. Recently in a multilingual project, there was a requirement to display Courses based on Language. And the Languages had to be shown as links. In order to achieve this functionality, the Views exposed filter had to be customized.

To start with the customization, we need to alter "views_exposed_form" using hook_form_alter

Continue reading →
knackforge blog

Drupal 7 - Exposing pseudo field in view from custom table

Introduction:

At KnackForge we often see requirement to expose custom fields to views for better integration with Drupal flow. In this article we are going to see steps to expose a custom field from a custom table. Infact its a virtual field. 

Use case:

Assume you have two custom fields total_marks and marks_obtained in a custom table. Now you need to calculate the percentage of mark scored. You don't need a field in table for this. You can create a virtual field bound to marks_obtained field.

Hooks to be used:

Continue reading →
knackforge blog

Altering views table output

Views module provides an easy way to render data from the Drupal database. It is often needed to use table output format to meet the design requirements. One such similar occasion needed customizing the table output.

The scenario was, we had a list of discounts with validity date as its one of the attributes. We wanted to show expired discounts in a different color to distinguish it from active discounts. What helped us was hook_preprocess_views_view_table().

Continue reading →
knackforge blog

Playing with Views API

Views, one of the most powerful module in the Drupal ecosystem. It has a great ability to create custom pages specific to project requirements from within Drupal admin interface without having to write any code. But at times it may become tedious even for the Views module to accomplish a few usecases. At such a point, things can be achieved programmatically by leveraging the API. This post aims at providing a practical piece of codes pertaining to Views for different scenario.

Continue reading →
knackforge blog

Creating mailchimp campaign from view output

MailChimp is a Web service offering platform for e-mail marketing. It is easy to start, use and scale. In short we can design, send, and track HTML email campaigns/newsletters with simple tools. There are  lot of things that makes us feel that MailChimp is the right choice for our needs. The list goes on with API to sync from inhouse sites/ applications, intuitive reports, integration with existing services like Facebook, Twitter and Google analytics, ability to create custom forms, etc. Of course we like MailChimp's humor as well. 

 

Continue reading →
knackforge blog

How to alter views field output programmatically

Amending the view output is no longer a tedious task. Especially by taking the advantage of settings available in Views 3.x like exclude from display, style settings, rewrite results and their sub-settings. The change can be anything simple from adding a <span> wrapper for CSS styling to complex token replacement (thanks to token module for making the Views module more awesome).

 

Continue reading →
knackforge blog

How to display views result count in Drupal 7

Views one of the prevailing modules in Drupal. It has the competence to dwindle manual work of pulling the data from Drupal table and formatting them to meet our needs. Most of the developers might have known about the filter and the sort criterion in the views, but only a few know the exact way to display the current items and total result count in this view. Does this requires acquaintance with coding? Apparently yes, but not as tedious as one would imagine. All it needs is a single line PHP print statement in view's template file.

Continue reading →