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?
-
Was my answer below helpful? – Rob Sanchez Oct 25 '13 at 19:20
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.