1

In function display_field(), if a fieldtype needs to use ee()->cp->add_to_head('/path/to/foo.css') and ee()->cp->add_to_foot('/path/to/bar.js'), how can I get it to do so only once, even when the Publish page may have multiple instances of that field?

1
  • Was my answer below helpful? – Rob Sanchez Oct 25 '13 at 19:20
5

Use the session cache:

if (ee()->session->cache(__CLASS__, __FUNCTION__) === FALSE)
{
  ee()->cp->add_to_head('/path/to/foo.css');

  ee()->session->set_cache(__CLASS__, __FUNCTION__, TRUE);
}

Your code will only run once per page load.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.