Search code examples
htmlerlangnitrogen

Nitrogen how to add element id


I can't figure out how to get Nitrogen to generate an actual id attribute of an html element. For example, In index.erl:

#panel { id = "test" } or #panel { id = test }

the generated html element looks like this:

<div class="wfid_test"></div>.

but what I want is:

<div id="test"></div>

so I can use an anchor link like <a href="#test">Scroll Down to Test</a> to reference the id.

This is basic HTML that has been around forever, so I'm sure Nitrogen must have some way of doing it, right?


Solution

  • Use 'html_id' element instead of 'id':

     #panel{ html_id=test, body="Test target" }
    

    it will render as:

    <div id="test" class="wfid_temp990008">Test target</div>
    

    you can include both 'id' and 'html_id' elements if you need the class for CSS as well:

    #panel{ id=test, html_id=test, body="Test target" }
    

    renders as:

    <div id="test" class="wfid_temp990008 wfid_test">Test target</div>