Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I return HTML in a virtual field? #15

Closed
dandv opened this issue Feb 25, 2014 · 6 comments
Closed

How do I return HTML in a virtual field? #15

dandv opened this issue Feb 25, 2014 · 6 comments

Comments

@dandv
Copy link
Contributor

dandv commented Feb 25, 2014

In a table with blog posts (title, author, date), I'd like to hyperlink the title to a page for the blog post. Ideally this would be an iron-router {{pathFor}}, but is there a way at least to return an HTML <a href="...computed slug..."> anchor?

@aslagle
Copy link
Owner

aslagle commented Feb 25, 2014

Yes, just create a Handlebars.SafeString from the HTML. See here for how I created the table library links. I don't think there's a way to use {{pathFor}}, but you can call the route's path function.

I should probably document this.

@aslagle
Copy link
Owner

aslagle commented Mar 1, 2014

Add to the documentation under Virtual Columns

@aslagle aslagle closed this as completed Mar 1, 2014
@dvzrd
Copy link

dvzrd commented Aug 25, 2014

Hello,

Can you explain how to call the route's path function please?

If I have a route setup that shows the detailed view of one item like this:

this.route('itemDetails', {
    path: '/items/:_id',
    waitOn: function() {
      return Meteor.subscribe('singleItem', this.params._id);
    },
    data: function() {
      return Items.findOne(this.params._id);
    }
});

How would I add a SafeString with a link to that path?

I set up an object in the fields array like this:

{
  key: '_id',
  label: 'Actions',
  fn: function (value) {
    return new Spacebars.SafeString('<a href="+Routes.route['itemDetails'].path({/items/_id:value})+"');
  }
}

But I'm getting some errors. Can you please point me in the right direction? Thanks a lot.

@brugnara
Copy link
Contributor

Firstly, this JSON completely wrong:

{/items/_id:value}
// should be
{'/items/_id':value}

Lastly:

You can use templates. Instead of fn, use a tmpl

tmpl: Template.item_operations

where Template.item_operations is something similar to this:

<a href="/items/{{value}}"> LINK HERE </a>

You can use Routes.route if you want. I've done this example just to show you how a template works.
Hope it helps.

@dvzrd
Copy link

dvzrd commented Aug 29, 2014

Thanks for the example and advice, this helped clear up my confusion.

@brugnara
Copy link
Contributor

Glad to help. You are welcome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants