Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add HTML id of item_id to paragraphs-item.tpl.php template #167

Closed
yorkshire-pudding opened this issue Feb 17, 2024 · 9 comments · Fixed by #168
Closed

Add HTML id of item_id to paragraphs-item.tpl.php template #167

yorkshire-pudding opened this issue Feb 17, 2024 · 9 comments · Fixed by #168
Labels
enhancement New feature or request has pr Has a PR or branch for testing.

Comments

@yorkshire-pudding
Copy link
Contributor

yorkshire-pudding commented Feb 17, 2024

Nodes have an id that relates to the node id (nid)

<article id="node-227"

It would be good, for the purposes of being able to navigate to a paragraph via an anchor link, to have the same in the template for paragraphs_item. For example.

<div id="paragraphs-item-37"

Where 37 is the item_id of the paragraphs item.

I tried to do this in a paragraphs-item.tpl.php file in my theme, and it worked, but I couldn't then do any other paragraphs-item templates to override more specific paragraph types.

@yorkshire-pudding
Copy link
Contributor Author

@laryn - I've added a PR that mirrors the way node.tpl.php does it

@herbdool
Copy link
Contributor

herbdool commented Mar 14, 2024

This looks good to me. This can be useful for things like adding links to hashes.

@laryn
Copy link
Member

laryn commented Mar 20, 2024

@yorkshire-pudding @herbdool What are your thoughts on whether we should preprocess and use backdrop_html_id for this?

Probably the core node implementation should do that too -- there are certainly cases I could see where a paragraph or node could be displayed more than once on a page, perhaps with different view modes, in a block, etc., and the current implementation would result in multiple identical id values.

@yorkshire-pudding
Copy link
Contributor Author

@laryn
I did think about using preprocess to prepare the variable and therefore make the template file have a much simpler change, but erred on the side of copying core.
I hadn't thought about the possibility of displaying the same paragraph twice, but that does strengthen the case for using preprocess, and using the function you suggest.

@albanycomputers
Copy link
Member

Does the "apenty" module fulfill this need, it has the "heading" type where you can create an anchor.

@yorkshire-pudding
Copy link
Contributor Author

Does the "apenty" module fulfill this need, it has the "heading" type where you can create an anchor.

There is a need for this in paragraphs without installing additional modules

@yorkshire-pudding
Copy link
Contributor Author

@laryn - I have updated this PR to use backdrop_html_id() within the preprocess function.

Tested by embedding the node again on the page in a block.
First one is id="paragraphs-item-1" and second is id="paragraphs-item-1--2"

@yorkshire-pudding
Copy link
Contributor Author

@laryn - a reminder that there is an updated PR awaiting your review

@yorkshire-pudding yorkshire-pudding added the has pr Has a PR or branch for testing. label Aug 15, 2024
@laryn laryn closed this as completed in 0d6d249 Aug 16, 2024
@laryn
Copy link
Member

laryn commented Aug 16, 2024

Thanks for your work here @yorkshire-pudding -- merged.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
enhancement New feature or request has pr Has a PR or branch for testing.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants