doublesecretagency / craft-cpcss

Control Panel CSS plugin for Craft CMS
MIT License
117 stars 8 forks source link

Inject Twig Code into CSS #16

Closed ammannbe closed 2 years ago

ammannbe commented 2 years ago

Hi there

  1. Just wanted to ask if it's somehow possible to inject some twig code into the CSS (file)?
    • Reason: I want to conditionally hide elements based on .env/config variables.
  2. Is it possible to set the CSS File(s) path in the config file? This would be very helpful if you are working with a version system like Git.

Thanks for your help :)

lindseydiloreto commented 2 years ago

Hi @ammannbe,

  1. Try moving your CSS file into the templates directory, so that Craft has a chance to parse out any Twig tags. You'll end up with a weird hybrid file, and I generally wouldn't recommend this approach, but it should do what you want. Another option is to make good use of the {% css %} tag within your existing Twig templates.

  2. Yup, this should already be possible! The "CSS File" field can accept an alias or environmental variable.

Hope that helps!

ammannbe commented 2 years ago

Hi @lindseydiloreto

I've already tried your approach to put the file into the templates folder - without any success. Do you have any idea?

Thanks!

lindseydiloreto commented 2 years ago

Not sure why it's not working. You may want to hop over to Craft Discord and describe the issue in greater detail.