byrge
December 15, 2017, 6:51am
1
Hi,
I’m using the viewcounts plug-in https://github.com/perlkonig/grav-plugin-count-views , but now I’m looking into how to display the “viewcounts” per page.
With a for key, value in viewcounts I get all the data in my page, but I don’t know how to get the value (viewcounts) for the page I’m currently viewing in my browser.
Anyone an idea?
Regards,
Byrge
byrge
December 18, 2017, 7:02pm
2
I tried a lot of possible things like:
{% if viewcounts %}
viewcount : {{ viewcounts.getName(data) }}
{% endif %}
or
{{ viewcounts|first }} – this gives me the first, but I want the count of the page I’m visiting
{{ viewcounts(value) }} or {{ viewcounts(page.route) }} or {{ viewcounts(data) }} or {{ viewcounts.data }} …
I tried the key (data) or the slug (page.route) or the value directly, but so far no luck.
Anybody a clue how to get the correct value for the page.route slug?
The data file is:
/: 28
/blog/sunshine-in-the-hills: 91
/blog/focus-and-blur: 48
The dump is:
{"/":28,"/blog/sunshine-in-the-hills":91,"/blog/focus-and-blur":50,"/blog/london-industry":1,"/blog/classic-modern-architecture":1}
1 Like
hi!
it works for me:
{% for route,view in viewcounts %}
{% if route == page.route() %}
<p>count view: {{ viewcounts[route] }}</p>
{% endif %}
{% endfor %}
byrge
February 12, 2018, 11:58am
4
Hi,
Thank you, I’ll try out your solution.
Regards,
Byrge
This work very good for totally viewcount of the page but there is a way to show also the count per day?
Thanks a lot.