0

How can I ensure that the headScript and headStyle helper include css files only once when added?

The reason I am asking is that I would like to display some contents in a lightbox and all Flashmassages.E.g. notifications like profile successfully edited.

To display flashmessages in the lightbox i would like to check at the top of my layout script if they are set, in case they are i would like to attach the required javascript library using the headScript helper.

The problem is that I have no control about the scripts which were already added at this point. Maybe at a page where the library is needed for an other use case, it has already been added with addScript.

How can I ensure all scripts are added only once to my helper?

I already checked that these helpers extend Zend_View_Helper_Placeholder_Container_Standalone which uses an ArrayObject internally to hold the data and provides getters & setter to the array object.

Maybe a solution here would be to check each time when adding a script file if it already exists using the ArrayObject?

1 Answer 1

1

As long as the paths and filenames are the same, the files will only be added once. The Zend View Helpers should take care of that for you.

Sign up to request clarification or add additional context in comments.

2 Comments

I tested this before asking the question and I experienced it differently but I am going to test it again now.
this solved it. maybe i just had typing errors in the first test I made before asking

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.