# Render hooks for tables?

**URL:** <https://discourse.gohugo.io/t/render-hooks-for-tables/37550>\
**Category:** support\
**Created:** [March 8, 2022, 6:31am UTC](https://discourse.gohugo.io/t/render-hooks-for-tables/37550 "2022-03-08T06:31:50Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![UtkarshVerma](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/utkarshverma/32/11273_2.png) [@UtkarshVerma](https://discourse.gohugo.io/u/UtkarshVerma)\
**Post date:** [March 8, 2022, 6:31am UTC](https://discourse.gohugo.io/t/render-hooks-for-tables/37550/1 "2022-03-08T06:31:50Z")

</div>

Currently, we have render-hooks for images, anchor tags, and headings. Are there any plans for implementing render-hooks for tables as well?

I use Bootstrap and tables in Bootstrap need to have classes like “table”, “table-\*” for styling them. For now, I made a shortcode as a hack to apply these classes to `.Inner`. But I feel it would be really great if we had render-hooks for tables as well.

```nohighlight
{{ .Inner | markdownify | replaceRE "<table>" (printf `<table class="table %s">` (.Get 0 | default "")) | safeHTML }}

```

---

<div class="post-metadata">

**Author:** ![davidsneighbour](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/davidsneighbour/32/24507_2.png) [@davidsneighbour](https://discourse.gohugo.io/u/davidsneighbour)\
**Post date:** [March 8, 2022, 6:46am UTC](https://discourse.gohugo.io/t/render-hooks-for-tables/37550/2 "2022-03-08T06:46:59Z")

</div>

I “fixed” this requirement by creating a class “prose” for my content. That prose class then is receiving all the classes required in the SCSS, something like this:

```nohighlight
.prose {
table {
  .dark & {
    @extend .table-dark;
  }

  .light & {
    @extend .table-light;
  }

  @extend .table;
  @extend .table-sm;
}
}

```

I think a render hook would be great, but will be hard to implement, because it requires more than just one single loop around the code (as in `<a>something</a>`) for headers/footers, rows and definitions for instance for column span, width etc…

---

<div class="post-metadata">

**Author:** ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)\
**Post date:** [March 8, 2022, 7:20am UTC](https://discourse.gohugo.io/t/render-hooks-for-tables/37550/3 "2022-03-08T07:20:46Z")

</div>

If you simply need to apply one or more classes to the \<`table`\> element…

config.toml

```nohighlight
[markup.goldmark.parser.attribute]
block = true

```

markdown

```nohighlight
Name|Type
:--|:--
Spot|Dog
Felix|Cat
{.table .foo}

```

---

<div class="post-metadata">

**Author:** ![Tom\_Durand](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/tom_durand/32/14460_2.png) [@Tom\_Durand](https://discourse.gohugo.io/u/Tom_Durand)\
**Post date:** [December 25, 2022, 1:10pm UTC](https://discourse.gohugo.io/t/render-hooks-for-tables/37550/4 "2022-12-25T13:10:32Z")

</div>

I don’t get why it should be difficult, given that tables end up rendered anyway so hugo knows the bonds of the object, doesn’t it?

---

<div class="post-metadata">

**Author:** ![bep](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bep/32/3332_2.png) [@bep](https://discourse.gohugo.io/u/bep)\
**Post date:** [December 25, 2022, 4:13pm UTC](https://discourse.gohugo.io/t/render-hooks-for-tables/37550/5 "2022-12-25T16:13:36Z")

</div>

The reason why we haven’t done this is not about how hard it would be to implement. The render hooks comes with a significant performance cost meaning the hooks needs to add significant value (which is the case for links, images and headings).

---

<div class="post-metadata">

**Author:** ![system](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/system/32/1_2.png) [@system](https://discourse.gohugo.io/u/system)\
**Post date:** [December 27, 2022, 4:13pm UTC](https://discourse.gohugo.io/t/render-hooks-for-tables/37550/6 "2022-12-27T16:13:56Z")

</div>

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.
