Skip to content

Support for Multiple Custom Plugin Scripts in froala_widget.html.twig #134

@DevShaun1

Description

@DevShaun1

Description

The README suggests that multiple custom plugin and button scripts can be loaded using the customJS option:

# Custom JS file.
# Usage: add custom plugins/buttons...
customJS: "/custom/js/path"

However, the src/Resources/views/Form/froala_widget.html.twig file currently only accommodates a single string for the froala_customJS variable:

{% if froala_customJS is defined %}
     <script type="text/javascript"  src="{{ asset( customJS ) }}"></script>
{% endif %}

Additionally, as referenced in Issue #127, the correct variable name passed to asset() should be froala_customJS.

Problem

This implementation does not allow for an array of scripts to be passed and iterated through, which limits flexibility for users who need to load multiple scripts.

Suggested Solution

Update the Twig template to handle both a single string and an array of scripts for froala_customJS. The logic should maintain backward compatibility, loading a single script if a string is provided or iterating through an array if multiple scripts are specified. Below is the proposed code update:

{% if froala_customJS is defined %}
    {% if froala_customJS is iterable %}
        {% for script in froala_customJS %}
            <script type="text/javascript" src="{{ asset(script) }}"></script>
        {% endfor %}
    {% else %}
        <script type="text/javascript" src="{{ asset(froala_customJS) }}"></script>
    {% endif %}
{% endif %}

Benefits

  • Supports both single string and array formats for froala_customJS.
  • Maintains backward compatibility with existing implementations.
  • Provides greater flexibility for users to load multiple custom plugins or buttons.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions