Getting CSS from module

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
steph_30
Forum Members
Forum Members
Posts: 22
Joined: Mon Apr 28, 2008 11:38 pm
Location: France

Getting CSS from module

Post by steph_30 »

Hi All,

I'm actually writting a module.
In this module , I use CMSMailer to send a mail : I get the cmsmailer module, fill the body and send.

But, the body is a HTML page (I'm using $smarty->ProcessTemplate('myTemplate') to get it), and I need to retrieve the according css.

So my question is : How do I get, from the module script, the css' that are linked to my actual page ?

And optionally, how do I get one css that is stored in the CMS database ?


Thanks for your help

Stephane
Wishbone
Power Poster
Power Poster
Posts: 1368
Joined: Tue Dec 23, 2008 8:39 pm

Re: Getting CSS from module

Post by Wishbone »

Code: Select all

// Create a instance of the StylesheetOperations class

$style_ops = $gCms->getStylesheetOperations();

// Get an array of stylesheet ID's from your template (my template was #21)

$style_ids = $style_ops->GetTemplateAssociatedStylesheets(21);

// Loop through your stylesheet ids and load the contents into a $stylesheet array

foreach ($style_ids as $style_id) {
  $stylesheet[$style_id] = $style_ops->LoadStylesheetByID($style_id);
}

// Print out a single stylesheet (my stylesheet id was 42)

echo($stylesheet[42]->value);

// You can also access $stylesheet[42]->name to get the stylesheet name
steph_30
Forum Members
Forum Members
Posts: 22
Joined: Mon Apr 28, 2008 11:38 pm
Location: France

Re: Getting CSS from module

Post by steph_30 »

Thanks wishbone,

I will try it tomorrow.

Just a last question :
Do I have to know the page Id or is it possible to get the associate CSS with the alias of my page in a king of :

$style_ids = $style_ops->GetTemplateAssociatedStylesheets(My_Alias);



For Dr.CSS :
I know that HTML email are not very easy to manage ... but they work pretty fine if the CSS is in the mail body.
That's why I want the css content and not only the file name (or id).
I will put it directly in the body of the mail. The mail content is not a very rich page, but only a summary. So it doesn't need to be very beautiful ...

Hey Doc, when I searched on css in the forum, You were the first one ...  ;D

If it work, I will close the topic

Thanks a lot

Stephane
Wishbone
Power Poster
Power Poster
Posts: 1368
Joined: Tue Dec 23, 2008 8:39 pm

Re: Getting CSS from module

Post by Wishbone »

steph_30 wrote: Do I have to know the page Id or is it possible to get the associate CSS with the alias of my page in a king of :

$style_ids = $style_ops->GetTemplateAssociatedStylesheets(My_Alias);
You need to supply the template id, not the page id.. If you only know the template name, there is a routine called "CheckExistingTemplateName" in TemplateOperations, where it looks like you can pass a name, where you can then get the id, then do what I suggested above.
steph_30
Forum Members
Forum Members
Posts: 22
Joined: Mon Apr 28, 2008 11:38 pm
Location: France

Re: Getting CSS from module

Post by steph_30 »

Thanks a lot for the answer.

I will try it today (with the template name first and the template ID if it doesn't work)  and reply to let you know the result.

So let's go to work ....


Stephane
steph_30
Forum Members
Forum Members
Posts: 22
Joined: Mon Apr 28, 2008 11:38 pm
Location: France

Re: Getting CSS from module

Post by steph_30 »

So I'm back with a solution to my problem.

To wishbone :

I tried the script you gave me, and it works fine.
I tried also the "CheckExistingTemplateName" function , but it only returned true or false if the template exists (it's quiet normal according to the function's name).

But finally, I'm using only the {stylesheet} smarty tag.
I juste insert this tag on the beginning of the mail body.

It generates a mail with link to stylesheets :
  So when you receive this mail, you've got a really poor (graphically) mail, but your mail software (like thunderbird) will tell you that the styles and images can be downloaded : it's the effect I wanted.

It works fine for me because I'm actually in a module and I'm comming from a page with a template and some related css. And finally, {stylesheet} just put the correct links to these related css.

So really cms ms is simple ...  ;)


Thanks a lot for your help

Stephane
Post Reply

Return to “Developers Discussion”