HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Pocket link that adapts to category being viewed
id2d
New
Just a quick question about pockets.
Is there a way to generate a link dependent on the category the discussion being viewed is in?
For example,
Viewing a thread in the "Widgets" category.
The Pocket link might go to http://mymainsite/help/widgets
"widgets" being appended to the end of the url as above.
0
Comments
Not possible?
I thought it was something really easy I was missing and was embarrassed to ask
I would say you need some javascript. But IDK if it can detect the changing page URL from within a pocket.
https://stackoverflow.com/questions/43722881/change-link-url-to-a-different-link-depending-on-the-page
https://blog.vanillaforums.com/product/power-pockets-adding-custom-html-js-vanilla-forum
Thanks
My first thought was doing something like this. But the page url for a discussion doesn't reveal the category it's in, so I looked at the page source and was having problems (can't remember why off the top of my head. Might have been that where the category is listed didn't have and id or class nearby to grab onto with javascript - my ability level anyway).
But then I came here because I was sure I was overcomplicating things and there must be an easier way.
Take a look at adding a conditional in the blog I linked to.
This might help
http://www.smarty.net/docsv2/en/language.function.if.tpl
You can get the category from the gdn.meta objet. Try
console.log(gdn.meta.eventData.discussion.category.categoryID);
in the console. As you will see, the category name is also available, if you prefer that.@Kaspar Thanks for that. But really looking for something that will work in a pocket for now. But I've bookmarked that as it's really useful and given me a few ideas about other things.
@R_J That actually works really well!! But only when viewing a discussion. Ideally I'd need something that works in the category list as well.
If that's all that's available will have to make a more complex script that changes based on if person viewing index or an actual thread - my pathetic javascript skills allowing!
The condition examples in the blog is in/for a pocket
That's a very good hint! You could also use a custom theme and in that theme you should be not only able to use $Category.CategoryID, but also $Discussion.CategoryID
If you want to stick to the js approach, take a look at the body class. It should have body.Categories.Category-thecategoryname
Ah that can go into pockets?
I had a go but all I got was the smarty on the page. I'll look through the documentation rather than lazily having a cut and paste 😁
No, Smarty code isn't recognized inside a pocket, as far as I know. The link explains what you can put into your themes default.master.tpl in order to conditionally show content.
So in order to do so, you would have to create different pockets and then include a Smarty snippet in your theme (please use your own custom theme if you decide to do so) where you want to show the pocket, e.g. at the bottom of the side panel: https://github.com/vanilla/vanilla/blob/master/addons/themes/keystone/views/default.master.tpl#L285