Skip to content

Commit

Permalink
Merge pull request #701 from City-of-Helsinki/UHF-X_handle_empty_comp…
Browse files Browse the repository at this point in the history
…onent_fields_better

UHF-X: Add better checking for empty title and description fields in components
  • Loading branch information
Arkkimaagi authored Jun 29, 2023
2 parents 7dc58ca + 34733cf commit e108738
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions templates/misc/component.twig
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,24 @@ Example usage:
{% set tag = 'div' %}
{% endif %}

{# Check if the fields are empty, ignore html comments, non-breaking spaces (  and character) and whitespace. #}
{% set hasTitle = component_title|render|striptags|replace({" ":" "," ":" "})|trim %}
{% set hasDescription = component_description|render|striptags|replace({" ":" "," ":" "})|trim %}

<div{{ component_attr.addClass('component', component_classes) }}>

{% if component_koro %}
{% include '@hdbt/misc/koro.twig' with component_koro %}
{% endif %}

<div class="component__container">

{% if component_title|render %}
{% if hasTitle %}
<{{ component_title_level|default('h2') }} class="component__title">
{{ component_title }}
</{{ component_title_level|default('h2')}}>
{% endif %}

{% if component_description|render %}
{% if hasDescription %}
<div class="component__description user-edited-content">
{{ component_description}}
</div>
Expand Down

0 comments on commit e108738

Please sign in to comment.