cancel
Showing results for 
Search instead for 
Did you mean: 

Set template content-type(mimeType) of output. (web)

drozes
Champ in-the-making
Champ in-the-making
Hi guys;

Been struggling with this for over 5 days now.

My quickstart site works well but I would like to change the content-type(mimeType) that it outputs to the browser.

You'll notice that most pages get outputted as html/text.

Is there a way to set the headers on a template to have it output to the browser as text/css ?

Thanks for any help.
7 REPLIES 7

rdanner
Champ in-the-making
Champ in-the-making
Hi guys;

Been struggling with this for over 5 days now.

My quickstart site works well but I would like to change the content-type(mimeType) that it outputs to the browser.

You'll notice that most pages get outputted as html/text.

Is there a way to set the headers on a template to have it output to the browser as text/css ?

Thanks for any help.

Set your webscript type to css

And then in a spring context file for alfresco/share you need to make CSS a valid type of webscript response

   <bean parent="webscripts.formatmap">
      <property name="formats">
         <props>
            <prop key="css">text/css</prop>
         </props>
      </property>
   </bean>

drozes
Champ in-the-making
Champ in-the-making
Hi russ;
I've added the bean with no issues.

The issue I do have is that the css is not being delivered directly though a web-script but rather a template.
The Temlates  ftl just uses Streamasset directive.

(the URL  hostSmiley Tongueost/context/css/style.css
The file style.css has the template css assigned to render it.  The css template is below.

Is it possible to set the output type of a template?


css.xml
<?xml version="1.0" encoding="UTF-8"?>
<template-instance>
   <title>css</title> 
     <description>Template to display contents of a CSS file</description>
      <template-type>css</template-type>      
   <content>text/css</content>
</template-instance>

css.ftl
<@streamasset asset=asset/>

rdanner
Champ in-the-making
Champ in-the-making
Hi russ;
I've added the bean with no issues.

The issue I do have is that the css is not being delivered directly though a web-script but rather a template.
The Temlates  ftl just uses Streamasset directive.

(the URL  hostSmiley Tongueost/context/css/style.css
The file style.css has the template css assigned to render it.  The css template is below.

Is it possible to set the output type of a template?


css.xml
<?xml version="1.0" encoding="UTF-8"?>
<template-instance>
   <title>css</title> 
     <description>Template to display contents of a CSS file</description>
      <template-type>css</template-type>      
   <content>text/css</content>
</template-instance>

css.ftl
<@streamasset asset=asset/>

To answer directly: I am not sure.

To answer indirectly:
You are using a template itself to render a CSS file?  Is this because the CSS is dynamic? 
* If it's not dynamic why not serve it as a static file?
* If it is dynamic (I'm guessing it is,) why not use a webscript instead?

/R

drozes
Champ in-the-making
Champ in-the-making
Hi Russ - Firstly - I am Greatly Appreciative of your efforts and really wish there was a way to 'give you rep' in this forum.


Yup, the CSS is dynamic and handled through the Document Library to allow for workflows to be integrated into it.


If i use a webscript, would the link inside my html page be something like:
<link href="http://hostSmiley Tongueort/appcontext/service/scriptToLoadCss?pathToFile=[]" rel="stylesheet" type="text/css" />

This is fine - I'd write a helper method to include CSS files.   My current issues would be the following:
Here is my current urlrewrite file.  If I can get this to let me access webscript through the browser, I think this plan would work for sure.


<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 3.1//EN"
        "./dtd/urlrewrite3.1.dtd">

<urlrewrite default-match-type="wildcard">

   <!– Spring Surf –>
   <!– Not required by quickstart
   <rule>
      <from>/proxy**</from>
      <to>/service/proxy/$1</to>
   </rule>
   <rule>
      <from>/res/**</from>
      <to>/service/resource/$1</to>
   </rule>
      
   <rule>
      <from>/service/**</from>
      <to>/service/$1</to>
   </rule>   
   –>
   
   
   <rule match-type="regex">
       <from>/(core-css|core-js|img|core-images|swf)/.*</from>
       <set name="static">true</set>
   </rule>   
   
   <rule>
        <condition type="attribute" name="static" operator="notequal">true</condition>
        <from>/service/**</from>
        <to>/dev/$1</to>
   </rule>
  
   <rule>
       <condition type="attribute" name="static" operator="notequal">true</condition>
      <from>/**</from>
      <to>/service/$1</to>
    </rule>   
   
   
   <outbound-rule>
      <from>/service/**</from>
      <to>/$1</to>
   </outbound-rule>
      
</urlrewrite>

scouil
Star Contributor
Star Contributor
There actually is a way to "give rep". At the right of each post you'll see a "Post rating: Useful? Yes / No" text if you're the original poster.
Clicking yes would give 1 point to the person.

About the webscript, you're right it would be called this way:
<link href="http://host:port/appcontext/service/scriptToLoadCss?pathToFile=[]" rel="stylesheet" type="text/css" />

I don't know a thing about url rewriting or your environment. It worked out of the box for me on the few configuration I've tried.
Can't help you with this one sorry.

.get.css.ftl  doesn't exists to my knowledge.
I'd personnally use plain text ftl and use the "negotiate" (http://wiki.alfresco.com/wiki/Web_Scripts#Advanced_Description_Options) attribute of the webscript.

Regards,

rmorant
Champ in-the-making
Champ in-the-making
If you assign ws:article=raw template in a folder then DynamicPageViewResolver use StreamedAssetView to render the raw content.

Put a css file into the folder and set the mime type to text/css.
Drozes: you can use the javascript console to do that.

var file = space.childByNamePath("site.css");
file.mimetype = "text/css";

And the url looks like:
<link href="http://host:port/appcontext/folder/site.css" rel="stylesheet" type="text/css" />

drozes
Champ in-the-making
Champ in-the-making
Worked-  Something about that Raw page template works well.

thanks!