Forums / Setup & design / {literal} in articles?

{literal} in articles?

Author Message

Jeroen Sangers

Friday 09 June 2006 8:47:50 am

Sometimes I want to enter some literal HTML or JavaScript text on a page, for example when I want to add a little tracking code to measure the result of an advertising campaign. At this moment the only way of doing so is by generating a template override for that specific page and enter the page there. That is a lot of work! Besides that, it is still impossible to add HTML in the middle of a text.
Is there really no way to have the equivalent of {literal} work inside articles?

Marcin Drozd

Friday 09 June 2006 3:07:38 pm

Hi Jeroen
It works with:

<literal class='html'>
some code
</literal>

http://ez-publish.pl

Jeroen Sangers

Wednesday 14 June 2006 2:15:43 am

Thanks! I must have read over it when I checked the documentation.

Ciprian Popovici

Wednesday 14 June 2006 2:23:11 am

The only thing <literal> does is create a <pre> block and apply wash() to everything in it. Doing class='blabla' only produces a <pre class='blabla'>, with everything inside it still washed.

Jeroen, I'm thinking you could accomplish this by creating your own custom tag, as well as an "unwash" eqivalent, some kind of reverse wash.

<b>Step 1:</b> Go in <b>both</b> the admin siteaccess and in the siteaccess you want to use this, and add this to custom.ini.append.php (create them if they don't exist):

[CustomTagSettings]
AvailableCustomTags[]=html
IsInline[html]=true

<b>Step 2:</b> Go to settings/override/template.ini.append.php and create an unwash function:

[PHP]
PHPOperatorList[unwash]=html_entity_decode

<b>Step 3:</b> Create the override, by going to design/yoursite/templates/content/datatype/view/ezxmltags/ and creating html.tpl with this in it:

{$content|unwash()}

<b>Step 4:</b> Clear your ini cache (possibly your template cache too).

<b>Step 5:</b> In the admin interface, every time you edit an XML block you can now add something like this:

<custom name='html'>&raquo;</custom>

...or whatever other HTML you want.

Jeroen Sangers

Wednesday 14 June 2006 2:49:22 am

That is not true!
The solution provided by Marcin Drozd works perfectly. It does not create a PRE block, but enters the provided code directly into the final page. There is no need to set up custom tags.

Marcin Drozd

Wednesday 14 June 2006 7:04:28 am

Hi guys
Yes,
<literal> creates <pre> tag, but
<literal class='html'> does not create <pre> tag.

http://ez-publish.pl

Ciprian Popovici

Thursday 15 June 2006 4:58:21 am

What ez Publish version are you using? On my 3.7.2 install, if I put HTML tags or HTML entities inside <literal class='html'></literal>, they end up escaped. Perhaps it's something else I'm missing? Did you guys override your literal template to do that?

If I put this in an XML block:

<literal class="html"><u>&raquo;</u></literal>

It will be rendered as:

<pre class="html">&lt;u&gt;&amp;raquo;&lt;/u&gt;</pre>

and NOT like this:

<u>&raquo;</u>

...thus negating the original request: ability to enter HTML or JavaScript code.

Jeroen Sangers

Thursday 15 June 2006 7:12:43 am

I am using eZ Publish 3.8.

Ciprian Popovici

Thursday 15 June 2006 7:24:07 am

Ah, there you go. They must've added this in 3.8. Anyway, for 3.7 users you have to resort to tricks like above. You could override the template for <literal> (haven't tried it), test for $class being "html" and apply unwash() on $content if it matches.