Announcement

Do not use the forums to submit bug reports, feature requests or patches, submit a New Ticket instead.

#1 2005-03-31 22:00:40

glebushka
Xinha Community Member
From: Moscow
Registered: 2005-02-26
Posts: 11
Website

template toolkit + xinha= problem?

I use Template Toolkit (http://www.template-toolkit.org/ -  template processing system). Directives are inserted in the document within the special markup tags which are '[%' and '%]'.
For example:
[% IF color=="blue" %]
Xinha changes in:
[% IF color==&quote;blue&quote; %]
or
<input type=hidden name=component_id value=[% component.component_id %]>
Xinha chages in
<input type="hidden" value="[%" name="component_id" />
sad
How I can "say" to Xinha that text within [% %] it mustn't processing?

Offline

#2 2005-04-01 04:00:08

adamp
Xinha Pro
Registered: 2005-03-14
Posts: 77

Re: template toolkit + xinha= problem?

It can't really not process them as it causes problems having HTML 'special' characters as input values. What you'd have to do is change the values within the [% %] tags back again before you save.

I don't know if you use PHP or not, but if you do you could do something like this before saving:

<?php
$text = $_POST['text'];

function addquotes ($matches) {
    
    $fixed_tag = str_replace("&quote;", "\"", $matches[1]);
    
    return $fixed_tag;
    
}

$text = preg_replace_callback("/\[%(.*?)%\]/si", "addquotes", $text);
?>

I haven't tested the above, but it should at the least give you an idea of what to do.

Offline

#3 2005-04-01 10:42:19

glebushka
Xinha Community Member
From: Moscow
Registered: 2005-02-26
Posts: 11
Website

Re: template toolkit + xinha= problem?

adamp, your offer doesn't solve problem. I can't correctly process on the server side changes like following:
when string

<input type=hidden name=component_id value=[% component.component_id %]>

transformes into

<input type="hidden" value="[%" name="component_id" />

Offline

#4 2005-04-01 10:46:06

Foxx
Xinha Community Member
Registered: 2005-02-20
Posts: 41

Re: template toolkit + xinha= problem?

<input type=hidden name=component_id value=[% component.component_id %]>

it is always recommended to put quotes around your attribute values anyways, maybe if you insert them yourself before hand, like so:

<input type="hidden" name="component_id" value="[% component.component_id %]" />

then maybe the problem will be solved!

Offline

#5 2005-04-01 10:50:59

glebushka
Xinha Community Member
From: Moscow
Registered: 2005-02-26
Posts: 11
Website

Re: template toolkit + xinha= problem?

Foxx. Yes. You are right. But templates are used not only by me. It will very irritably for users:(

Offline

#6 2005-04-01 10:54:25

adamp
Xinha Pro
Registered: 2005-03-14
Posts: 77

Re: template toolkit + xinha= problem?

glebushka wrote:

adamp, your offer doesn't solve problem. I can't correctly process on the server side changes like following:
when string

<input type=hidden name=component_id value=[% component.component_id %]>

transformes into

<input type="hidden" value="[%" name="component_id" />

This example is a different problem to your original question though.

If you don't put quotes around values, then browsers will split them off wherever a space occurs. It should be simple enough for your users to put quotes around values and at least that way they're writing correct HTML.

Offline

#7 2005-04-01 11:04:31

glebushka
Xinha Community Member
From: Moscow
Registered: 2005-02-26
Posts: 11
Website

Re: template toolkit + xinha= problem?

adamp, read my first posting more attentively. I wrote this example in my first posting.
If [% component.component_id %] after work of template processor converts in 843. We also recive correct HTML:
<input type=hidden name=component_id value=843>
Quotes are not required in this case. Especially because we may have following code:
<input type=hidden name=component_id value="[% IF my_param == "2" %][% some_function %][% ELSE %]none[% END %]">
I put quotes. As you see. But it doesn't solve problem:(

Offline

#8 2005-04-01 11:19:49

adamp
Xinha Pro
Registered: 2005-03-14
Posts: 77

Re: template toolkit + xinha= problem?

In which case what you're trying to do is not feasible as standard. Xinha is a WYSIWYG, so it has to display any code you give it, but it of course doesn't have the functionality of the template engine.

You could try writing a 'code shielding' function as has been suggested for hiding PHP code, but there's no ready-made solution.

Basically what you would do is have some kind of image that is shown when in WYSIWYG view, where the alt tag of the image has the code being hidden. This wouldn't necessarily work for you however, as putting an image inside an input value causes even more problems.

As long as you don't want to edit the template codes (the [% ... %] bits), you could write a script to pull them all out (using a similar regex to the code I gave before) and hide them in a set of hidden inputs which are then put back in when you save the template.

e.g. say you had this code:

<form action="[% component.formpath %]" method="post">
<input type=hidden name=component_id value=[% component.component_id %]>
<input type="submit" />

You would write some code where each template tag is pulled out into an array that gets passed separately from the WYSIWYG contents, so the first tag becomes something like [tag_1], the second becomes [tag_2] and so on and you then have an array where $array[1] has the value "[% component.formpath %]" and $array[2] has the value "[% component.component_id %]"

You can then pass the array either with the form or as a session value and put them back in before saving the template (i.e. you swap bacl [tag_1] for $array[1] etc.)

In other words, there's no easy solution from the info you've given.

Offline

#9 2005-04-02 05:24:24

gogo
Xinha Leader
From: New Zealand
Registered: 2005-02-11
Posts: 1,015
Website

Re: template toolkit + xinha= problem?

glebushka wrote:

<input type=hidden name=component_id value=843>
Quotes are not required in this case.

Quotes should always be used.

Especially because we may have following code:
<input type=hidden name=component_id value="[% IF my_param == "2" %][% some_function %][% ELSE %]none[% END %]">

That's invalid HTML, the inner quotes must be entities.

To put it simply, in WYSIWYG mode, Xinha can only deal with perfectly valid HTML. That means that quotes will, and must, be entities except where they delimit an attribute value.

If you want to use invalid HTML such as the above you will have to "massage" it so that is IS valid html when you give it to Xinha, and "massage" the valid html that Xinha gives you back into your invalid-html markup.


James Sleeman

Offline

Board footer

Powered by FluxBB