backdrop-contrib / paragraphs

Paragraphs module to control your content flow
https://backdropcms.org/project/paragraphs
GNU General Public License v2.0
5 stars 11 forks source link

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

Open yorkshire-pudding opened 5 months ago

yorkshire-pudding commented 5 months ago

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 commented 5 months ago

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

herbdool commented 4 months ago

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

laryn commented 4 months ago

@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 commented 4 months ago

@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 commented 4 weeks ago

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

yorkshire-pudding commented 4 weeks ago

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 commented 4 days ago

@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"