rendering plaintext with freemarker?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

rendering plaintext with freemarker?

Tobias Jeger
Hi Hippos,

in order to simplify the installation of the robotstxt plugin, I try to use a Freemarker template rather than JSP.
The robots.txt resource provided by the plug-in should have a Content-Type of "text/plain" (not HTML).

So far, I haven't managed to get the desired Content-Type out of the Freemarker template. Google wasn't helping
much on the Freemarker side of things, and the HST documentation didn't help on the HST side of things. I tried

response.setContentType("text/plain")

in RobotstxtComponent#doBeforeRender(), but still I get back text/html. So I wonder if Freemarker is bound to HTML,
or if anybody has the knowledge on how to get this adjusted?

thanks

Tobi


--
Amsterdam - Oosteinde 11, 1017 WT Amsterdam
Boston - 1 Broadway, Cambridge, MA 02142

US +1 877 414 4776 (toll free)
Europe +31(0)20 522 4466
www.onehippo.com

_______________________________________________
Hippo-cms7-user mailing list and forums
http://www.onehippo.org/cms7/support/forums.html
Reply | Threaded
Open this post in threaded view
|

Re: rendering plaintext with freemarker?

Wouter Danes-2

The HstFreemarkerServlet handles the freemarker templates. It’s an extension of the FreemarkerServlet from Freemarker.

Check FreemarkerServlet.java#428 (Under Hippo 7.7, version 2.3.18 of freemarker-sources.jar):

        Object attrContentType = template.getCustomAttribute("content_type");

        if(attrContentType != null) {

            response.setContentType(attrContentType.toString());

        }

        else {

            if (noCharsetInContentType) {

                response.setContentType(

                        contentType + "; charset=" + template.getEncoding());

            } else {

                response.setContentType(contentType);

            }

        }

 

So the servlet is initialized with a contenttype and a template can have a custom contenttype.

My guess is the standard hippo servlet is initialized with contenttype “text/html”..

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Tobias Jeger
Sent: donderdag 24 januari 2013 16:15
To: Hippo CMS 7 implementation list
Subject: [Hippo-cms7-user] rendering plaintext with freemarker?

 

Hi Hippos,

in order to simplify the installation of the robotstxt plugin, I try to use a Freemarker template rather than JSP.
The robots.txt resource provided by the plug-in should have a Content-Type of "text/plain" (not HTML).

So far, I haven't managed to get the desired Content-Type out of the Freemarker template. Google wasn't helping
much on the Freemarker side of things, and the HST documentation didn't help on the HST side of things. I tried

response.setContentType("text/plain")

in RobotstxtComponent#doBeforeRender(), but still I get back text/html. So I wonder if Freemarker is bound to HTML,
or if anybody has the knowledge on how to get this adjusted?

thanks

Tobi


--

Amsterdam - Oosteinde 11, 1017 WT Amsterdam
Boston - 1 Broadway, Cambridge, MA 02142

US +1 877 414 4776 (toll free)
Europe +31(0)20 522 4466
www.onehippo.com


_______________________________________________
Hippo-cms7-user mailing list and forums
http://www.onehippo.org/cms7/support/forums.html
Reply | Threaded
Open this post in threaded view
|

Re: rendering plaintext with freemarker?

Woonsan Ko-3
The following message informs of how to set a custom attribute such as
content_type in a freemarker template. It might be worth trying it:

http://freemarker.624813.n4.nabble.com/customAttribute-and-content-type-td626177.html

Cheers,

Woonsan

On 1/24/13 4:31 PM, Wouter Danes wrote:

> The HstFreemarkerServlet handles the freemarker templates. It’s an
> extension of the FreemarkerServlet from Freemarker.
>
> Check FreemarkerServlet.java#428 (Under Hippo 7.7, version 2.3.18 of
> freemarker-sources.jar):
>
>          Object attrContentType =
> template.getCustomAttribute("content_type");
>
>          if(attrContentType != null) {
>
>              response.setContentType(attrContentType.toString());
>
>          }
>
>          else {
>
>              if (noCharsetInContentType) {
>
>                  response.setContentType(
>
>                          contentType + "; charset=" +
> template.getEncoding());
>
>              } else {
>
>                  response.setContentType(contentType);
>
>              }
>
>          }
>
> So the servlet is initialized with a contenttype and a template can have
> a custom contenttype.
>
> My guess is the standard hippo servlet is initialized with contenttype
> “text/html”..
>
> *From:*[hidden email]
> [mailto:[hidden email]] *On Behalf Of
> *Tobias Jeger
> *Sent:* donderdag 24 januari 2013 16:15
> *To:* Hippo CMS 7 implementation list
> *Subject:* [Hippo-cms7-user] rendering plaintext with freemarker?
>
> Hi Hippos,
>
> in order to simplify the installation of the robotstxt plugin, I try to
> use a Freemarker template rather than JSP.
> The robots.txt resource provided by the plug-in should have a
> Content-Type of "text/plain" (not HTML).
>
> So far, I haven't managed to get the desired Content-Type out of the
> Freemarker template. Google wasn't helping
> much on the Freemarker side of things, and the HST documentation didn't
> help on the HST side of things. I tried
>
> response.setContentType("text/plain")
>
> in RobotstxtComponent#doBeforeRender(), but still I get back text/html.
> So I wonder if Freemarker is bound to HTML,
> or if anybody has the knowledge on how to get this adjusted?
>
> thanks
>
> Tobi
>
>
> --
>
> Amsterdam - Oosteinde 11, 1017 WT Amsterdam
> Boston - 1 Broadway, Cambridge, MA 02142
>
> US +1 877 414 4776 (toll free)
> Europe +31(0)20 522 4466
> www.onehippo.com <http://www.onehippo.com/>
>
>
>
> _______________________________________________
> Hippo-cms7-user mailing list and forums
> http://www.onehippo.org/cms7/support/forums.html
>


--
[hidden email]     www.onehippo.com
Boston - 1 Broadway, Cambridge, MA 02142
Amsterdam - Oosteinde 11, 1017 WT Amsterdam
US +1 877 414 4776 (toll free)
Europe +31(0)20 522 4466
_______________________________________________
Hippo-cms7-user mailing list and forums
http://www.onehippo.org/cms7/support/forums.html
Reply | Threaded
Open this post in threaded view
|

Re: rendering plaintext with freemarker?

Woonsan Ko-3
Hi Tobias / Wouter,

I've just realized that the example in the thread causes a parsing
exception because it doesn't include double quotes for the content_type
custom attribute name.
So, if you add the following line in your freemarker template, then you
can simply override the default content type header for your template:

<#ftl attributes={"content_type": "text/plain" } />
...

Note you use {"content_type": "..."}, not {content_type: "..."}.

Kind regards,

Woonsan


On 1/24/13 5:13 PM, Woonsan Ko wrote:

> The following message informs of how to set a custom attribute such as
> content_type in a freemarker template. It might be worth trying it:
>
> http://freemarker.624813.n4.nabble.com/customAttribute-and-content-type-td626177.html
>
>
> Cheers,
>
> Woonsan
>
> On 1/24/13 4:31 PM, Wouter Danes wrote:
>> The HstFreemarkerServlet handles the freemarker templates. It’s an
>> extension of the FreemarkerServlet from Freemarker.
>>
>> Check FreemarkerServlet.java#428 (Under Hippo 7.7, version 2.3.18 of
>> freemarker-sources.jar):
>>
>>          Object attrContentType =
>> template.getCustomAttribute("content_type");
>>
>>          if(attrContentType != null) {
>>
>>              response.setContentType(attrContentType.toString());
>>
>>          }
>>
>>          else {
>>
>>              if (noCharsetInContentType) {
>>
>>                  response.setContentType(
>>
>>                          contentType + "; charset=" +
>> template.getEncoding());
>>
>>              } else {
>>
>>                  response.setContentType(contentType);
>>
>>              }
>>
>>          }
>>
>> So the servlet is initialized with a contenttype and a template can have
>> a custom contenttype.
>>
>> My guess is the standard hippo servlet is initialized with contenttype
>> “text/html”..
>>
>> *From:*[hidden email]
>> [mailto:[hidden email]] *On Behalf Of
>> *Tobias Jeger
>> *Sent:* donderdag 24 januari 2013 16:15
>> *To:* Hippo CMS 7 implementation list
>> *Subject:* [Hippo-cms7-user] rendering plaintext with freemarker?
>>
>> Hi Hippos,
>>
>> in order to simplify the installation of the robotstxt plugin, I try to
>> use a Freemarker template rather than JSP.
>> The robots.txt resource provided by the plug-in should have a
>> Content-Type of "text/plain" (not HTML).
>>
>> So far, I haven't managed to get the desired Content-Type out of the
>> Freemarker template. Google wasn't helping
>> much on the Freemarker side of things, and the HST documentation didn't
>> help on the HST side of things. I tried
>>
>> response.setContentType("text/plain")
>>
>> in RobotstxtComponent#doBeforeRender(), but still I get back text/html.
>> So I wonder if Freemarker is bound to HTML,
>> or if anybody has the knowledge on how to get this adjusted?
>>
>> thanks
>>
>> Tobi
>>
>>
>> --
>>
>> Amsterdam - Oosteinde 11, 1017 WT Amsterdam
>> Boston - 1 Broadway, Cambridge, MA 02142
>>
>> US +1 877 414 4776 (toll free)
>> Europe +31(0)20 522 4466
>> www.onehippo.com <http://www.onehippo.com/>
>>
>>
>>
>> _______________________________________________
>> Hippo-cms7-user mailing list and forums
>> http://www.onehippo.org/cms7/support/forums.html
>>
>
>


--
[hidden email]     www.onehippo.com
Boston - 1 Broadway, Cambridge, MA 02142
Amsterdam - Oosteinde 11, 1017 WT Amsterdam
US +1 877 414 4776 (toll free)
Europe +31(0)20 522 4466
_______________________________________________
Hippo-cms7-user mailing list and forums
http://www.onehippo.org/cms7/support/forums.html
Reply | Threaded
Open this post in threaded view
|

Re: rendering plaintext with freemarker?

Tobias Jeger
Thanks Woonsan,

that saves me the debugging!

cheers

Tobi


On Mon, Jan 28, 2013 at 6:26 AM, Woonsan Ko <[hidden email]> wrote:
Hi Tobias / Wouter,

I've just realized that the example in the thread causes a parsing exception because it doesn't include double quotes for the content_type custom attribute name.
So, if you add the following line in your freemarker template, then you can simply override the default content type header for your template:

<#ftl attributes={"content_type": "text/plain" } />
...

Note you use {"content_type": "..."}, not {content_type: "..."}.

Kind regards,

Woonsan



On 1/24/13 5:13 PM, Woonsan Ko wrote:
The following message informs of how to set a custom attribute such as
content_type in a freemarker template. It might be worth trying it:

http://freemarker.624813.n4.nabble.com/customAttribute-and-content-type-td626177.html


Cheers,

Woonsan

On 1/24/13 4:31 PM, Wouter Danes wrote:
The HstFreemarkerServlet handles the freemarker templates. It’s an
extension of the FreemarkerServlet from Freemarker.

Check FreemarkerServlet.java#428 (Under Hippo 7.7, version 2.3.18 of
freemarker-sources.jar):

         Object attrContentType =
template.getCustomAttribute("content_type");

         if(attrContentType != null) {

             response.setContentType(attrContentType.toString());

         }

         else {

             if (noCharsetInContentType) {

                 response.setContentType(

                         contentType + "; charset=" +
template.getEncoding());

             } else {

                 response.setContentType(contentType);

             }

         }

So the servlet is initialized with a contenttype and a template can have
a custom contenttype.

My guess is the standard hippo servlet is initialized with contenttype
“text/html”..

*From:*[hidden email]
[mailto:[hidden email]] *On Behalf Of
*Tobias Jeger
*Sent:* donderdag 24 januari 2013 16:15
*To:* Hippo CMS 7 implementation list
*Subject:* [Hippo-cms7-user] rendering plaintext with freemarker?

Hi Hippos,

in order to simplify the installation of the robotstxt plugin, I try to
use a Freemarker template rather than JSP.
The robots.txt resource provided by the plug-in should have a
Content-Type of "text/plain" (not HTML).

So far, I haven't managed to get the desired Content-Type out of the
Freemarker template. Google wasn't helping
much on the Freemarker side of things, and the HST documentation didn't
help on the HST side of things. I tried

response.setContentType("text/plain")

in RobotstxtComponent#doBeforeRender(), but still I get back text/html.
So I wonder if Freemarker is bound to HTML,
or if anybody has the knowledge on how to get this adjusted?

thanks

Tobi


--

Amsterdam - Oosteinde 11, 1017 WT Amsterdam
Boston - 1 Broadway, Cambridge, MA 02142

US <a href="tel:%2B1%20877%20414%204776" value="+18774144776" target="_blank">+1 877 414 4776 (toll free)
Europe <a href="tel:%2B31%280%2920%20522%204466" value="+31205224466" target="_blank">+31(0)20 522 4466
www.onehippo.com <http://www.onehippo.com/>



_______________________________________________
Hippo-cms7-user mailing list and forums
http://www.onehippo.org/cms7/support/forums.html





--
[hidden email]     www.onehippo.com
Boston - 1 Broadway, Cambridge, MA 02142
Amsterdam - Oosteinde 11, 1017 WT Amsterdam
US <a href="tel:%2B1%20877%20414%204776" value="+18774144776" target="_blank">+1 877 414 4776 (toll free)
Europe <a href="tel:%2B31%280%2920%20522%204466" value="+31205224466" target="_blank">+31(0)20 522 4466
_______________________________________________
Hippo-cms7-user mailing list and forums
http://www.onehippo.org/cms7/support/forums.html



--
Amsterdam - Oosteinde 11, 1017 WT Amsterdam
Boston - 1 Broadway, Cambridge, MA 02142

US +1 877 414 4776 (toll free)
Europe +31(0)20 522 4466
www.onehippo.com

_______________________________________________
Hippo-cms7-user mailing list and forums
http://www.onehippo.org/cms7/support/forums.html