in this post, i'll show you how to add loop index in paragraph.html.twig
using hook_
preprocess_field(&$variables){}
/**
* @param $variables
*/
function mytheme_preprocess_field(&$variables) {
if($variables['field_name'] == 'field_paragraph_name'){
foreach($variables['items'] as $idx => $item) {
$variables['items'][$idx]['content']['#paragraph']->index = $idx;
}
}
}
and then in your paragraph.html.twig
file you can use {{ paragraph.index }}
{% if paragraph.index == 0 %}
<li class="accordion-item is-active">
{% else %}
<li class="accordion-item">
{% endif %}