Creating a page dynamically Using Views in Drupal 7 I can consume the output of a restful API. I want to take some of the data and dynamically create pages. For example I get the following return json:

$data = {'title':'This is a page title','alias':'pages/page-alias-name','content':'This is some content'}


I would want to dynamically create a page located at http://www.example.com/pages/page-alias-name which would have a title of $data['title'] and the content would be $data['content']. Is it possible to create pages dynamically like this. How can I go about doing this?

Additionally, if I had identical content stored in an external database that can be read by a custom Views module, can I do this and how would I go about it?
I'm not sure how you are using Views to do this, but with a custom module you could easily do this with a fairly simple hook_menu(), eg, something along these lines:

function YOURMODULE_menu() {

  $items=array();

  $items['pages'] = array(
    'page callback' =&gt; 'YOURMODULE_get_some_rest',
    'access callback' =&gt; TRUE,
  );

  // any other menu items go here

  return $items;

}


and then:

function YOURMODULE_get_some_rest() {

  $args=func_get_args();

  if ($args) {

    $alias='pages/' . implode('/', $args); // so pages/foo works as does pages/foo/bar etc

    $data = /* get your data from your external service */ ;

    if ( /* $data was found */ ) {

      drupal_set_title( /* title in $data */ );

      return /* content in $data */ ;

    } else {

      return MENU_NOT_FOUND; // we don't have an alias of that name

    }

  } else {

    return MENU_NOT_FOUND;  // just called 'pages' so do something else here if need be, perhaps a list of all pages but for now, we just return not found

  }

}


so after a cache clear, users should now be able to go to www.example.com/pages/alias and Drupal will go out to your external service and grab the content and if found, populate the page with it, otherwise will return not found.

Now, if this data is going to be fairly static, I'd look into caching it so your users aren't delayed while Drupal fetches it.  For that, I'd look into cache_set() and cache_get().

ADDITION:

Drupal's menu system works on a sort of best fit methodology.  For example, if you define a menu item foo, it will obviously match www.example.com/foo, but, if no menu item has been defined for foo/bar, it will also match www.example.com/foo/bar or even www.example.com/foo/bar/baz/bing etc etc.

So, in my example above, I defined pages.  This will match www.example.com/pages which is just an error condition above, but with some programming could list all of the potential pages you have available to you, but also will match www.example.com/pages/alias-of-page or www.example.com/pages/alias/of/page.

Inside the callback, I use PHP's built-in function func_get_args() to deal with the variable number of arguments that can be passed to this function.  When you go to www.example.com/pages, no arguments will be passed to this callback and func_get_args() will return an empty array.  But, when you go to www.example.com/pages/alias-to-page, Drupal will automatically pass alias-to-page to the callback, and func_get_args() will return an array containing it, and when you go to www.example.com/pages/alias/to/page, it will pass three arguments, alias, to, and page to the callback function and func_get_args() will return an array containing all three.

As to your commentary question regarding this inside Views, once again, I'm not sure how your are doing this inside Views, but yes, this would go inside YOURMODULE.module and would stand alone outside of Views (although Views might be a great place to generate the listing on pages by itself).