Problem/Motivation

Adding anchors to the h2 category titles on the page will allow the use of anchor links to each category. E.g. /node/add#category

Proposed resolution

A small update to the type-tray-page.html.twig template.

CommentFileSizeAuthor
#2 3376834-category-anchors-2.patch554 bytesminirobot

Comments

minirobot created an issue. See original summary.

minirobot’s picture

StatusFileSize
new554 bytes

Adding a patch.

minirobot’s picture

Issue summary: View changes

marcoscano’s picture

Status: Active » Fixed

Looks good to me, thanks for contributing!
My nitpicky brain has a tendency to complain that there's nothing guaranteeing that at the template level the {{ category }} variable will be CSS-safe (in theory it could be almost any string), but I believe the idea is that these would be unique, machine-names, and it's fairly safe to assume them as CSS ids, so let's go forward with this.
Thanks! 👍
(released https://www.drupal.org/project/type_tray/releases/1.2.3 with this)

penyaskito’s picture

+++ b/templates/type-tray-page.html.twig
@@ -42,7 +42,7 @@
     <div class="type-tray-category category--{{ category }}">
...
+      <h2 id="{{ category }}">{{ category_labels[category] }}</h2>

I think this is safe, and if it weren't the problem already existed before the patch (see div class).

We can probably use |clean_class in both for going the safer route.

hawkeye.twolf’s picture

+1 for always using `|clean_class` when printing classes in a template! :D

hawkeye.twolf’s picture

Also thank you Betty for the patch and thank you Marcos for such a quick release!!!! :D

  • marcoscano committed 1f3e4d1f on 1.0.x
    Issue #3376834 by minirobot, penyaskito, hawkeye.twolf, marcoscano: Add...
marcoscano’s picture

Sounds good, thanks all!
(and apologies for pulling the trigger too fast! :D )

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.