How to distinguish the home page of the category page?
-
-
mod.widgetsGet = function(data, callback) { template = data.templates[1].replace('.tpl', ''); if ( template == 'categories' ){ console.log('Home page opened'); } else if ( template == 'category' ){ console.log('Subcategory page opened'); } else if ( template == 'topic' ){ console.log('Topic page opened'); } callback(null, data.data); };
-
If I understand you correctly, It sounds like you should be adding this to your widget or theme.
I don't think adding a filter is what you want to do. Filters are used to modify data, an "action" would be better if you're trying to figure out when a specific widget area is requested. But, this would not be useful in this regard because it's also called on the ACP Widget page.
What you probably want to do is use the existing "filter:widget.render:widgetname" hook,
plugins.fireHook('filter:widget.render:' + widget.widget, { uid: uid, area: area, data: widget.data }
The area that is passed has area.template already.
-
@yariplus I can not understand why in the data that is returned fireHook only widget.data?
-
In the code
src/widgets.js
file seems to be all right. -
@sergej-saveljev That's okay, it is a little confusing. The hook returns uid, area, and data. For example, the function you would assign to "filter:widget.render:widgetname" would be like:
mod.renderWidget = function(data, callback) { console.log(data.area.template); // This is the template you are looking for. console.log(data.data); // This is the Widget's setting data. console.log(data.uid); // This is the User who is viewing the page. return callback(); }
-
@yariplus returned
undefined
for all console.log calls -
Did you create the widget? It won't work if there's no widget to render.
Do you have a link to your full code?
-
@yariplus said:
Did you create the widget? It won't work if there's no widget to render.
Do you have a link to your full code?
Yes, I created widget. I deleted code, but he was about, how you wrote.
-
Hmm, I'm not sure why it wouldn't work then, that's pretty much exactly my code.