Using a templating language like Jinja2, you could use the following template:
The following changes have been made to the main page:
Instruction IDs Added
{% for instruction_id in added_instruction_ids %}
Instruction ID #{{instruction_id.id}}
{% endfor %}
Instruction IDs Removed
{% for instruction_id in removed_instruction_ids %}
Instruction ID #{{instruction_id.id}}
{% endfor %}
You could even achieve your "dynamic template" request by using if statements:
The following changes have been made to the main page:
{% if len(added_instruction_ids) %}
Instruction IDs Added
{% endif %}
{% for instruction_id in added_instruction_ids %}
Instruction ID #{{instruction_id.id}}
{% endfor %}
{% if len(removed_instruction_ids) %}
Instruction IDs Removed
{% endif %}
{% for instruction_id in removed_instruction_ids %}
Instruction ID #{{instruction_id.id}}
{% endfor %}
Note: the above examples assume that the following data is passed to the template engine:
{
added_instruction_ids: [
{
id: X,
url: link_to_url_of_instruction_id_X
}, {
id: Y,
url: link_to_url_of_instruction_id_Y
}
],
removed_instruction_ids: [
{
id: A,
url: link_to_url_of_instruction_id_A
}
]
}