角度のあるアプリを呼び出すために使用しているカットム モジュールを含む Drupal サイトがあります。
モジュールコードは次のとおりです。
/**
* Implements hook_menu().
*/
function portfolio_menu() {
$items = array();
$items['portfolio'] = array(
'access arguments' => array('access content'),
'title' => t('Portfolio'),
'page callback' => 'portfolio_page',
);
return $items;
}
/**
* Page callback: Displays Your Application on the page.
*
* @see your_application_menu()
*/
function portfolio_page() {
$path = drupal_get_path('module', 'portfolio');
drupal_add_js($path . '/lib/angular/angular.js');
drupal_add_js($path . '/lib/angular/angular-resource.js');
drupal_add_js($path . '/js/services.js');
drupal_add_js($path . '/js/app.js');
drupal_add_js($path . '/js/controllers.js');
drupal_add_js($path . '/js/filters.js');
drupal_add_css($path . '/css/app.css');
drupal_add_css($path . '/css/bootstrap.css');
return theme('portfolio');
}
function portfolio_theme($existing, $type, $theme, $path) {
$theme = array();
$theme['portfolio'] = array(
'variables' => array(),
'template' => 'portfolio',
);
return $theme;
}
app.js:
angular.module('portfolio', ['tickerFilters', 'tickerServices']).
config(['$routeProvider', function($routeProvider) {
$routeProvider.
when('/tickers', {templateUrl:'...portfolio/partials/ticker-list.html', controller: TickerListCtrl}).
otherwise({redirectTo: '/tickers'});
}]);
これは、drupal によって読み込まれた最後の tpl.php ファイルです。
<div ng-app="portfolio" ng-init="user = <? json_encode($user); ?>">
<div ng-view></div>
</div>
私の質問は、角度アプリで $user データを使用できるように、アプリを呼び出すときに drupal $user オブジェクトを角度に渡す方法です。