Skip to content
This repository has been archived by the owner on Nov 20, 2022. It is now read-only.

No shared CSS #1

Closed
mciszczon opened this issue Mar 25, 2017 · 4 comments
Closed

No shared CSS #1

mciszczon opened this issue Mar 25, 2017 · 4 comments

Comments

@mciszczon
Copy link

This is not a bug, but there's almost exactly the same CSS stored in three different places.

site/plugins/content-viewer/widget/template.php
site/plugins/content-viewer/templates/content-viewer.php
site/plugins/content-viewer/templates/content-viewer-source.php

Of them, only site/plugins/content-viewer/templates/content-viewer.php has few CSS rules which are not shared, but it would be easy to just overwrite them (as it's being done already).

The main problem is that you have to edit all these 3 files in order to change styling in all of these 3 views. Of course, sometimes you'd want to have different styles for each one. But that's perfectly fine if you have a shared base-style and then can easily build upon it or just overwrite what you want.

@calebgrove
Copy link
Owner

Thanks for the heads-up. First, you can delete site/plugins/content-viewer/templates/content-viewer-source.php, as it is a leftover from some experimentation and does nothing. I'll remove it in the next release.

Unfortunately, Kirby doesn't make it easy for plugin authors to add a CSS file to the panel, which is why I'm using <style> tags, and ultimately why there is duplication. The simplest solution would require each user of the plugin to add some code to their config file, which I'm loath to do as every additional required step is one more way for things to break. I'll give it some thought. Do you have any suggestions for methods to do this?

@mciszczon
Copy link
Author

mciszczon commented Mar 25, 2017

I actually have already done a quick (and probably not the cleanest) fix. Might as well fork and create a pull request, if you wish.

But you may do it yourself, here's everything you'll need: How to store plugin assets | Kirby.

Especially this:

As long as you store your assets in the assets folder, your assets are publicly available at the following URL:
http://{domain}/assets/plugins/{pluginName}/{optionalSubfolder}/{filename}

So you just create assets folder in the root of the plugin (site/plugins/content-viewer), put style.css there. Then you can echo the asset like always, using:
<?= css('assets/plugins/content-viewer/style.css') ?>.

Any additional styles might be then added to a particular template using <style>, but I guess that it would be better anyway to just add these styles to the style.css file and apply them with a class. For example, when viewing the file in a new window, I would just apply a class .new-window, and if viewing as a widget, the class wouldn't be applied. That's all.

Also, thanks for the plugin. Great work you're doing there! Keep it up for sure :)

@calebgrove
Copy link
Owner

Thanks @mciszczon! I'm implementing it as we speak.

calebgrove added a commit that referenced this issue Mar 26, 2017
@calebgrove
Copy link
Owner

Amongst a bunch of other things, it's fixed now in 1.2.0!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants