Can a module add CSS links to the head? [RESOLVED]

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
oi_antz

Can a module add CSS links to the head? [RESOLVED]

Post by oi_antz »

It seems to run in a literally procedural manner, start printing the template, get to the place where the {content} tag sits, then begin executing the module - is this correct?

My standard approach is to execute the controller then render the template, allowing Smarty to replace the markers before outputting the resulting page.

I have concerns about putting css and js links in the body, they should belong in the head.
Last edited by oi_antz on Mon Jul 21, 2008 9:01 pm, edited 1 time in total.
viebig

Re: Can a module add CSS links to the head?

Post by viebig »

a solution would be capture the module output and use a if statement on the head section of the template. Its doable
oi_antz

Re: Can a module add CSS links to the head?

Post by oi_antz »

What does "SAP" stand for? I can't find a reference to it regarding CMSms.
oi_antz

Re: Can a module add CSS links to the head?

Post by oi_antz »

viebig, how would I "capture the module output"? It seems to me that the module's DoAction is not called until after the head has been rendered, as I have tried putting Smarty markers in the head and setting the Smarty variables before DoAction is finished, they don't get populated. They do work when I put the markers below the {content} tag in the template.
viebig

Re: Can a module add CSS links to the head?

Post by viebig »

well, Smart Manual reading is a goos practice  :)

The idea is:

put this on the top of your template

Code: Select all

{capture assign='mynews'}{news}{/capture}
now you can replace the {news} tag with {$mynews}

and the next part is add a if statement inside you

Code: Select all

{if !empty($mynews)}

<!-- Put some code here, a script call or stylesheet -->

{/if}
sam_butler
Forum Members
Forum Members
Posts: 24
Joined: Sun Jul 20, 2008 3:36 pm
Location: Manchester, UK

Re: Can a module add CSS links to the head?

Post by sam_butler »

@oi_antz, did you get your question answered? It does run linearly so if you call the module within {content} then you won't get your CSS links. I had a problem where I needed to pass a variable in the content of several pages in order to set a different header image further up the template. I used:

Code: Select all

{capture assign='captured_content'}{content}{/capture}
...so that CMSMS is running with whatever I put in the content of the page. This went at the top of the template. If you assign variables in the content itself, or if you call a module there and it assigns vars, you can now call those vars thereafter, however you like. Then in the part of the template where you want your content, you just pop {$captured_content} instead.

It kinda depends on where you call the module to be perfectly honest.
Dee
Power Poster
Power Poster
Posts: 1197
Joined: Sun Mar 19, 2006 8:46 pm
Location: the Netherlands

Re: Can a module add CSS links to the head?

Post by Dee »

Modules can add stuff to the head section by creating a (overriding the parent class') ContentPostRender method.
The News and Album modules do this for example.
oi_antz

Re: Can a module add CSS links to the head?

Post by oi_antz »

Awesome! Several possible solutions, will have a go at it tonight. Cheers!
oi_antz

Re: Can a module add CSS links to the head? [RESOLVED]

Post by oi_antz »

Great solution is capturing. I never would have thought of using Smarty this way.

Here is my solution in the template:

Code: Select all

{capture assign='_CONTENT'}{content}{/capture}
<doctype>
<head>
... cmsms tags ...
{$_CSSLINKS}
{$_CSS}
{$_JSLINKS}
{$_JS}
{$_HEAD}
</head>
</__body>
... layout ...
{$_CONTENT}
... layout ...
<__body>
This allows the modules to use the $PAGE object to add css and javascript to the head:

Code: Select all

<?php
$PAGE->addCssLink('page_specific_styles.css');
sam_butler
Forum Members
Forum Members
Posts: 24
Joined: Sun Jul 20, 2008 3:36 pm
Location: Manchester, UK

Re: Can a module add CSS links to the head? [RESOLVED]

Post by sam_butler »

;)
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: Can a module add CSS links to the head? [RESOLVED]

Post by calguy1000 »

If you're writing a module, there's a very simple solution to this:

Call the module twice with different actions.  Once for the body and once for the head.


...
{MyModule action='headerjavascript'}
...


...
{MyModule action='whatever'}
...
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
Post Reply

Return to “Developers Discussion”