Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I assume there's some place in your application where you know whether the user is logged in or not. For the sake of argument I'll assume it's encapsulated in a function attached to a User object, which in turn is attached to the global App, so <code>MyApp.CurrentUser.isLoggedIn()</code>.</p> <p>One approach you could take is to add a dependency between the <code>RowItemView</code> and this <code>CurrentUser</code> object. When you're rendering the <code>RowItemView</code> test if the user is logged in and update the view accordingly.</p> <p>I'm making a lot of assumptions about your code here, but this snippet should demonstrate the basic idea:</p> <pre><code> onRender: function() { if (MyApp.CurrentUser.isLoggedIn()) { this.$('.js-edit').removeClass('hidden'); } } </code></pre> <p><em>Addendum</em></p> <p>So, you want to update multiple sections of your view? Try using the templateHelpers property:</p> <pre><code>TableView.RowItemView = Marionette.ItemView.extend({ template: /* resolves to: */ '&lt;td&gt;&lt;%= getItemOne() %&gt;&lt;/td&gt;' + '&lt;td&gt;&lt;%= getItemTwo() %&gt;&lt;/td&gt;', templateHelpers: { getItemOne: function() { if (window.isLoggedIn) { return 'Logged In Content'; } return 'Not Logged In Content'; }, getItemTwo: function() { if (window.isLoggedIn) { return 'Logged In Content'; } return 'Not Logged In Content'; } } </code></pre> <p>Since you say <code>isLoggedIn</code> is in the global namespace there's no need to pass it in. If you need to pass it in though, try:</p> <pre><code>TableView.RowItemView = Marionette.ItemView.extend({ initialize: function(options) { this.templateHelpers.isLoggedIn = options.isLoggedIn; // ... other work as needed }, templateHelpers: { getItemOne: function() { if (this.isLoggedIn) {} // should work now } } </code></pre> <p>The problem with this approach is that you're passing a variable from a CompositeView, which means you need to override the CompositeView's <code>buildItemView</code> property, which frankly seems like more work than its worth, but here's a snippit if you want to try it:</p> <pre><code>TableView.MainTable = Marionette.CompositeView.extend({ initialize: function(collection, options) { this.isLoggedIn = options.isLoggedIn; // ... }, buildItemView: function(item, ItemViewType, itemViewOptions){ var options = _.extend({model: item, isLoggedIn: this.isLoggedIn }, itemViewOptions); return new ItemViewType(options); }, </code></pre>
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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