Can a module add CSS links to the head? [RESOLVED]
Can a module add CSS links to the head? [RESOLVED]
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.
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.
Re: Can a module add CSS links to the head?
a solution would be capture the module output and use a if statement on the head section of the template. Its doable
Re: Can a module add CSS links to the head?
What does "SAP" stand for? I can't find a reference to it regarding CMSms.
Re: Can a module add CSS links to the head?
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.
Re: Can a module add CSS links to the head?
well, Smart Manual reading is a goos practice 
The idea is:
put this on the top of your template
now you can replace the {news} tag with {$mynews}
and the next part is add a if statement inside you

The idea is:
put this on the top of your template
Code: Select all
{capture assign='mynews'}{news}{/capture}
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}
-
- 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?
@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:
...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.
Code: Select all
{capture assign='captured_content'}{content}{/capture}
It kinda depends on where you call the module to be perfectly honest.
Re: Can a module add CSS links to the head?
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.
The News and Album modules do this for example.
Re: Can a module add CSS links to the head?
Awesome! Several possible solutions, will have a go at it tonight. Cheers!
Re: Can a module add CSS links to the head? [RESOLVED]
Great solution is capturing. I never would have thought of using Smarty this way.
Here is my solution in the template:
This allows the modules to use the $PAGE object to add css and javascript to the head:
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>
Code: Select all
<?php
$PAGE->addCssLink('page_specific_styles.css');
-
- Forum Members
- Posts: 24
- Joined: Sun Jul 20, 2008 3:36 pm
- Location: Manchester, UK
-
- 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]
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'}
...
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.
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.