Pinegrow Community Support Forum

Adding an external resource conditionally


#1

Hi guys,

another one:

Having this for loading an external stylesheet:

var res = new PgComponentTypeResource('https://clients.updog.co/Reginald-theMagicGrid/css/magicstyles.css');
res.type = 'text/css';
 f.resources.add(res);

That’s fine - however it appends it to all already existing sheets. Especially the default style.css . But it necessarily should load before the style.css (supposed for overwrite the external one).

If you could be so kind pointing me here as well into the correct direction.

Thanks in advance.

Cheers

Thomas


#2

you can use hasDetect on your new pgFramework Object if

              f = new pgFramework 
              f.detect = function(check){
                    return check.hasScript(put here script name); <<< this function will get a regular expersions or script name.
               }

#3

Thanks @itsmeleo

I have already this one in the plugin-script (adopted from the 960 grid example from @matjaz) but I’m certainly not really understanding it:

   //Auto detect 960 grid. It can also be manually added / removed from a page with Framework Manager
    f.detect = function (pgPage) {
        return pgPage.hasStylesheet(/(^|\/)960.*\.(css|less)/i);
    } 

Is it there to adjust the path?

Cheers

Thomas


#4

You have to change the RegEx here its only detecting 960grid if this css is added already so replace 960 with your css or add 960 in the name of your styles so they will get detected.