---
url: 'https://metadrop.net/es/articulos/agregar-vistas-en-codigo-en-distintos-ficheros-para-mejorar-legibilidad'
title: 'Agregar vistas en código en distintos ficheros para mejorar legibilidad'
author: 'Jorge Tutor'
date: '2017-01-17T10:26:23+00:00'
updated: '2026-06-10T06:58:14+00:00'
type: article
summary: 'Implementación de la API de views para tener las vistas en ficheros separados.'
tags:
  - 'Drupal 7'
  - 'Views (Drupal module)'
  - Drupal
published: true
og:
  determiner: Automatic
  site_name: Metadrop
  'image:alt': 'Agregar vistas en código en distintos ficheros para mejorar legibilidad'
  street_address: 'Calle Manuel Luna, 12, 3 Dcha'
  locality: Madrid
  region: Madrid
  postal_code: '28020'
  country_name: España
  email: hola@metadrop.net
  phone_number: '910053180'
schema:
  '@context': 'https://schema.org'
  '@graph':
    -
      '@type': Article
      '@id': 'https://metadrop.net/es/articulos/agregar-vistas-en-codigo-en-distintos-ficheros-para-mejorar-legibilidad#article'
      name: 'Agregar vistas en código en distintos ficheros para mejorar legibilidad'
      headline: 'Agregar vistas en código en distintos ficheros para mejorar legibilidad'
      description: 'Implementación de la API de views para tener las vistas en ficheros separados.'
      about:
        - 'Drupal 7'
        - 'Views (módulo de Drupal)'
        - Drupal
      datePublished: '2014-05-27T08:00:00+0200'
      dateModified: '2026-06-10T08:58:14+0200'
      author:
        '@type': Person
        name: 'Jorge Tutor'
      publisher:
        '@type': Organization
        '@id': 'https://metadrop.net/#organization'
      mainEntityOfPage: 'https://metadrop.net/es/articulos/agregar-vistas-en-codigo-en-distintos-ficheros-para-mejorar-legibilidad'
    -
      '@type': Organization
      '@id': 'https://metadrop.net/#organization'
      url: 'https://metadrop.net/'
      name: Metadrop
      sameAs:
        - 'https://www.drupal.org/metadrop'
        - 'https://twitter.com/metadrop'
        - 'https://asociaciondrupal.es/partner/metadrop'
        - 'https://www.linkedin.com/company/metadrop'
      logo:
        '@type': ImageObject
        url: 'https://metadrop.net/themes/custom/mdrop_radix/logo-metadrop-500-500.jpg'
        width: '500'
        height: '500'
    -
      '@type': ItemPage
      '@id': 'https://metadrop.net/es/articulos/agregar-vistas-en-codigo-en-distintos-ficheros-para-mejorar-legibilidad'
      breadcrumb:
        '@type': BreadcrumbList
        itemListElement:
          -
            '@type': ListItem
            position: 1
            name: Inicio
            item: 'https://metadrop.net/es'
          -
            '@type': ListItem
            position: 2
            name: 'Artículos expertos sobre Drupal y tecnología'
            item: 'https://metadrop.net/es/articulos'
      publisher:
        '@type': Organization
        '@id': 'https://metadrop.net/#organization'
---
 1. [Artículos](https://metadrop.net/es/articulos)
 
  

# Agregar vistas en código en distintos ficheros para mejorar legibilidad

Martes 27 de Mayo de 2014

 

 



Implementación de la API de views para tener las vistas en ficheros separados.



   



En ocasiones, es más práctico tener las vistas en ficheros separados para mejorar su legibilidad así como para tenerlo todo más ordenado en git. No debería de ser un gran problema de rendimiento localizar este fichero ya que queda cacheado.

Declaramos a views nuestra intención de utilizar su api:

Fichero: mymodule.module

```php
/**
 * Implementation of hook_views_api().
 */
function mymodule_views_api() {
  return array(
    'api' => 3,
    'path' => drupal_get_path('module', 'mymodule') . '/views',
  );
}
```

Snipet para que de forma automática coja todas las vistas en la carpeta mymodule/views que terminen en \*.view.inc

Fichero: views/mymodule.views\_default.inc

```php
/**
 * Implements hook_views_default_views().
 */
function mymodule_views_default_views() {
  // @NOTE: Load All views!
  $files = file_scan_directory(
    drupal_get_path('module', 'mymodule') . '/views',
    '/.*\.view.inc$/');
 
  foreach ($files as $file) {
    $view = NULL;
    // Including the view file definition:
    require $file->filename;
    if (!empty($view)) {
      $views[$view->name] = $view;
    }
  }
 
  return $views;
}
```



[Drupal 7](https://metadrop.net/es/articulos?text=Drupal%207)

[Views (módulo de Drupal)](https://metadrop.net/es/articulos?text=Views%20%28m%C3%B3dulo%20de%20Drupal%29)

[Drupal](https://metadrop.net/es/articulos?text=Drupal)

 

- Jorge Tutor
    
    CIO