Skip to content
Grav 2.1 is out: every page speaks Markdown. Read the announcement →

Viewcounts - see pageviews per page

Started by Byrge 9 years ago · 4 replies · 1176 views
9 years ago

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

9 years ago

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
9 years ago

Hi,

Thank you, I'll try out your solution.

Regards,
Byrge

Suggested topics

Topic Participants Replies Views Activity
General · by jeremycherfas, 4 days ago
3 95 3 hours ago
General · by Old Man Umby, 2 days ago
1 60 2 days ago
General · by Sebastian, 4 days ago
1 81 4 days ago
General · by Andy Miller, 2 weeks ago
0 216 2 weeks ago
General · by ready-4-IT, 6 months ago
1 716 3 weeks ago