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

Limited tag list #25

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions blueprints.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,10 @@ form:
placeholder: /blog
validate:
pattern: "/([a-z\-_]+/?)+"

limit:
type: number
label: Tag limit
min: 0
default: 0
placeholder: 0
1 change: 1 addition & 0 deletions taxonomylist.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
enabled: true
route: '/blog'
limit:
9 changes: 6 additions & 3 deletions templates/partials/taxonomylist.html.twig
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
{% set taxlist = children_only is defined ? taxonomylist.getChildPagesTags() : taxonomylist.get() %}
{% set limit = config.plugins.taxonomylist.limit %}

{% if taxlist %}
<span class="tags">
{% for tax,value in taxlist[taxonomy] %}
{% set active = uri.param(taxonomy) == tax? 'active' : '' %}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also does need this active state put back.

<a class="{{ active }}" href="{{ base_url }}/{{ taxonomy }}{{ config.system.param_sep }}{{ tax }}">{{ tax }}</a>
{% set count = 0 %}
{% for tax,value in taxlist[taxonomy] if count < limit %}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

count < limit could cause issues if you have no limit value. need to also check if limit is set before this if is evaluated

{% set label_class = uri.param(taxonomy) == tax ? 'label-primary' : 'label-secondary' %}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also changes class names. Not only the logic.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't touch anything, just add a condition in the loop which refers to a variable in the taxonomy.yaml, because I noticed that the plugin already put the tags in order from the most used one to the less used ones.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, the {% set active line has been removed, and you have introduced label-primary and label-secondary to the code. Your contribution is probably not originating from the plugin itself, but from a customized (themed?) twig.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, I forgot about my old modifications before posting the code.
I have to admit it: that's my first time posting something on github.
I'll amend the lines soon.

<a class="label label-rounded {{ label_class }}" title="{{ tax }}" href="{{ base_url_absolute }}/{{ taxonomy }}{{ config.system.param_sep }}{{ tax }}">{{ tax }}</a>
{% set count = count + 1 %}
{% endfor %}
</span>
{% endif %}