CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Discussion »
  • Extensions (Moderators: mathieu, totten, kasiawaka) »
  • How to add extension specific css stylesheet
Pages: [1]

Author Topic: How to add extension specific css stylesheet  (Read 2388 times)

awasson

  • I post frequently
  • ***
  • Posts: 230
  • Karma: 7
  • Living in a world of Drupal / CiviCRM
    • My Company: Luna Design
  • CiviCRM version: Latest
  • CMS version: Drupal 6/7/8
  • MySQL version: 5.x
  • PHP version: 5.3.x
How to add extension specific css stylesheet
December 22, 2012, 11:59:17 am
Hey all,

I'm getting the hang of how files within extensions are organized but I can't seem to figure out how I can load an extension specific css file so that it cascades with the rest of the css files in the head of a document. Is there any docs I can look at?

Thanks,
Andrew
My CiviCRM Extension Workshop: https://github.com/awasson

totten

  • Administrator
  • Ask me questions
  • *****
  • Posts: 695
  • Karma: 64
Re: How to add extension specific css stylesheet
January 05, 2013, 02:47:04 pm
Have you tried using "addStyle" (in PHP) or "{crmStyle}" in Smarty?

http://wiki.civicrm.org/confluence/display/CRMDOC42/Resource+Reference

awasson

  • I post frequently
  • ***
  • Posts: 230
  • Karma: 7
  • Living in a world of Drupal / CiviCRM
    • My Company: Luna Design
  • CiviCRM version: Latest
  • CMS version: Drupal 6/7/8
  • MySQL version: 5.x
  • PHP version: 5.3.x
Re: How to add extension specific css stylesheet
January 05, 2013, 05:53:51 pm
Quote from: totten on January 05, 2013, 02:47:04 pm
Have you tried using "addStyle" (in PHP) or "{crmStyle}" in Smarty?

http://wiki.civicrm.org/confluence/display/CRMDOC42/Resource+Reference

Thanks Totten,

I haven't tried either of those but I will read those resources and do so.

As a workaround, during development I've been adding style declarations to my tpl files in {literal} tags which at least keeps me going in the right direction.

Cheers,
Andrew
My CiviCRM Extension Workshop: https://github.com/awasson

awasson

  • I post frequently
  • ***
  • Posts: 230
  • Karma: 7
  • Living in a world of Drupal / CiviCRM
    • My Company: Luna Design
  • CiviCRM version: Latest
  • CMS version: Drupal 6/7/8
  • MySQL version: 5.x
  • PHP version: 5.3.x
Re: How to add extension specific css stylesheet
January 19, 2013, 09:26:15 pm
Hey Totten,

I'm using the "add a css file by extension CRM_Core_Resources::singleton()->addStyleFile('com.example.foo', 'bar.css');" method to include my stylesheet but rather than show the virtual path, I am seeing the file path to the css file with http:// in front of it.

Code: [Select]
http://localhost//Library/WebServer/Documents/sites/all/extensions/ca.lunahost.civitax/civitax_style.css
It should be:

Code: [Select]
http://localhost/sites/all/extensions/ca.lunahost.civitax/civitax_style.css
Any idea why that's happening?

My code is as follows:

Code: [Select]
CRM_Core_Resources::singleton()->addStyleFile('ca.lunahost.civitax', 'civitax_style.css');
Thanks,
Andrew
My CiviCRM Extension Workshop: https://github.com/awasson

totten

  • Administrator
  • Ask me questions
  • *****
  • Posts: 695
  • Karma: 64
Re: How to add extension specific css stylesheet
January 19, 2013, 10:22:13 pm
Try this:

1. Go "Administer => System Settings => Resource URLs"
2. Check "Extension Resource URL"

This box should contain the base URL of the extension directory. In this, it sounds like it would be "http://localhost/sites/all/extensions"

awasson

  • I post frequently
  • ***
  • Posts: 230
  • Karma: 7
  • Living in a world of Drupal / CiviCRM
    • My Company: Luna Design
  • CiviCRM version: Latest
  • CMS version: Drupal 6/7/8
  • MySQL version: 5.x
  • PHP version: 5.3.x
Re: How to add extension specific css stylesheet
January 19, 2013, 10:25:54 pm
Thanks... That was me  ::)

At some point I set the extension resource URL to: http://localhost//Library/WebServer/Documents/sites/all/extensions/ca.lunahost.civitax/civitax_style.css

Fixed it up and it works as expected.

Thanks,
Andrew
My CiviCRM Extension Workshop: https://github.com/awasson

awasson

  • I post frequently
  • ***
  • Posts: 230
  • Karma: 7
  • Living in a world of Drupal / CiviCRM
    • My Company: Luna Design
  • CiviCRM version: Latest
  • CMS version: Drupal 6/7/8
  • MySQL version: 5.x
  • PHP version: 5.3.x
Re: How to add extension specific css stylesheet
February 09, 2013, 10:25:24 am
Totten,

Is there a token I can use to reference my extension when I use:

Code: [Select]
CRM_Core_Resources::singleton()->addStyleFile('ca.lunahost.civitax', 'civitax_style.css');
On my dev machine, I'm using ca.lunahost.civitax however in the real world, it will likely be called civitax or something similar. I suppose I could request the PHP path and deconstruct it to get the name of the module's directory but thought I would check to see if there was a shorcut.

Thanks,
Andrew

EDIT: I've used the PHP path to file method. I stuffed the path to the my_extension.php file in an array, grabbed the second to last index and created variable that I can reference in the extension as needed.
« Last Edit: February 09, 2013, 12:54:35 pm by awasson »
My CiviCRM Extension Workshop: https://github.com/awasson

totten

  • Administrator
  • Ask me questions
  • *****
  • Posts: 695
  • Karma: 64
Re: How to add extension specific css stylesheet
February 20, 2013, 04:35:40 pm
I don't really understand why one would want to change the extension key on different installations. It seems like extra work to rename an extension when going from development to production, and it creates differences (read: potential breakage) between the dev/prod systems. Changing the key would also make it more complex to manage distribution through the in-app system (which, e.g., uses the key to find/download upgrades for the extension). For comparison: in programming languages that support package namespaces (like Java, .Net, PHP 5.3+), one doesn't change a class's namespace just because it's been installed on a different system.

Could you describe the situation/use-case a bit more?

awasson

  • I post frequently
  • ***
  • Posts: 230
  • Karma: 7
  • Living in a world of Drupal / CiviCRM
    • My Company: Luna Design
  • CiviCRM version: Latest
  • CMS version: Drupal 6/7/8
  • MySQL version: 5.x
  • PHP version: 5.3.x
Re: How to add extension specific css stylesheet
February 20, 2013, 05:32:19 pm
Yes, I probably haven't explained it well enough.

  • I have an extension ca.lunahost.civitax. The civix tool stubbed everything out quite nicely into a directory called ca.lunahost.civitax on my development machine. I'm using github for backup and version control. So far everything is great. Git keeps my extension in civiTax and when someone downloads it it will download as civiTax-master.zip, unpacking to a directory called civiTax-master.
     
  • If someone takes this extension from Github as is, installs and activates it, the root of the module will be somewhere like (Drupal system) /sites/all/extensions/civiTax-master
     
  • If I use CRM_Core_Resources::singleton()->addStyleFile('ca.lunahost.civitax', 'civitax_style.css'); to add my stylesheet to the mix, it is static and regardless of the name that the extension has it will always be at ca.lunahost-civitax/civitax_style.css
     

Note: If I use the ca.lunahost.civitax name format on Github, the extension path still work because it would unpack as ca.lunahost.civitax-master. 

If in order to prevent breaking things within the extesnion-module, I suppose there's nothing I can do but provide that sort of instruction to the end user (and myself)

Andrew

My CiviCRM Extension Workshop: https://github.com/awasson

totten

  • Administrator
  • Ask me questions
  • *****
  • Posts: 695
  • Karma: 64
Re: How to add extension specific css stylesheet
February 20, 2013, 06:50:59 pm
OK, good point -- if one manually extracts a Github zipball, then the directory name won't work correctly in 4.2 A few thoughts:

1) I think you're right that the the most effective solution for now is to provide instructions on naming the directory.

2) In 4.2, we used the rule that "the key is declared in info.xml, and the directory name should match it." I would expect things to break if they don't match, but by happenstance CRM_Core_Resources may work with the directory-name in lieu of the declared extension-key.

3) In 4.3, this will change. CRM_Core_Resources *must* use the extension-key (from info.xml) and not the directory-name. More generally, the directory-name won't matter. (If you've used Drupal much, you may have noticed that there's a *convention* to match the directory-name and module but it's not a hard requirement -- same idea. The system will locate extensions by doing a file-system search for info.xml files.)

4) If one uses the in-app distribution to install a Github "zipball", then 4.2 should rename the directory automatically. This probably doesn't help if you're doing private or alpha releases, but it's worth noting. (4.3 will help a bit with private/alpha releases -- you can use Drush or cli.php to download an extension even if it's not publicly listed; e.g. "drush cvapi extension.download key=ca.lunahost.civitax url=https://github.com/awasson/civiTAX/archive/master.zip" This will also fix-up the directory-name automatically.)

5) If one installs by cloning a Github repo, then you can specify the directory as part of the checkout (e.g. "git clone git://github.com/awasson/civiTAX.git ca.lunahost.civitax")

awasson

  • I post frequently
  • ***
  • Posts: 230
  • Karma: 7
  • Living in a world of Drupal / CiviCRM
    • My Company: Luna Design
  • CiviCRM version: Latest
  • CMS version: Drupal 6/7/8
  • MySQL version: 5.x
  • PHP version: 5.3.x
Re: How to add extension specific css stylesheet
February 20, 2013, 07:06:07 pm
Perfect! That makes perfect sense to me. When I noted the dependency on the naming convention, I figured it might break something by not adhering to it.

I'll reorganize things over on my Github account and add a note regarding the naming convention requirement in the info file.

Thanks for clearing that up for me  ;D
My CiviCRM Extension Workshop: https://github.com/awasson

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Discussion »
  • Extensions (Moderators: mathieu, totten, kasiawaka) »
  • How to add extension specific css stylesheet

This forum was archived on 2017-11-26.