Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I pass the $user object from drupal to an Angular JS app so angular can use it?
    primarykey
    data
    text
    <p>I have a Drupal site with a cutom module that I am using to call an angular app.</p> <p>here is the module code:</p> <pre><code>/** * Implements hook_menu(). */ function portfolio_menu() { $items = array(); $items['portfolio'] = array( 'access arguments' =&gt; array('access content'), 'title' =&gt; t('Portfolio'), 'page callback' =&gt; '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' =&gt; array(), 'template' =&gt; 'portfolio', ); return $theme; } </code></pre> <p>app.js:</p> <pre><code>angular.module('portfolio', ['tickerFilters', 'tickerServices']). config(['$routeProvider', function($routeProvider) { $routeProvider. when('/tickers', {templateUrl:'...portfolio/partials/ticker-list.html', controller: TickerListCtrl}). otherwise({redirectTo: '/tickers'}); }]); </code></pre> <p>here is the last tpl.php file loaded by drupal:</p> <pre><code>&lt;div ng-app="portfolio" ng-init="user = &lt;? json_encode($user); ?&gt;"&gt; &lt;div ng-view&gt;&lt;/div&gt; &lt;/div&gt; </code></pre> <p>my question is how do I pass the drupal $user object to angular when i call the app, so that the $user data can be used in the angular app?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload