How to output curly brackets - { } ?

A general technical discussion area for patTemplate.
Locked
User avatar
soeren
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 111
Joined: Mon Aug 29, 2005 10:58 am
Location: Germany
Contact:

How to output curly brackets - { } ?

Post by soeren » Mon Mar 06, 2006 3:59 pm

Hello,

How can I use curly brackets in templates / HTML code (which do not surround a variable name)?
I've recently come across the problem that a site which was created from patTemplate-parsed Templates didn't contain any curly brackets, which where in there before in a script section. The brackets were deleted!!

See this example...
BEFORE:

Code: Select all

<script type="text/javascript">
...
if( !(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(form.email.value))) {
    ....
}
</script>
But after the page was being parsed in a Joomla-template using patTemplate, the output was the following:

Code: Select all

<script type="text/javascript">
...
if( !(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w)+$/.test(form.email.value))) {
    ....
}
</script>
As you can see, the part {2,4} was deleted!! In consequence the regular expression always returns false.



ciao, Soeren

User avatar
Vimes
Joomla! Ace
Joomla! Ace
Posts: 1675
Joined: Fri Aug 19, 2005 12:14 am
Location: United Kingdom
Contact:

Re: How to output curly brackets - { } ?

Post by Vimes » Mon Mar 06, 2006 4:34 pm

Not looked at your post in depth, but suspect that this: http://www.w3.org/MarkUp/html-spec/html-spec_13.html

is what you're looking for. Left curly brace/Right curly brace
http://www.jomres.net THE online hotel booking and reservation system for Joomla and Wordpress.

User avatar
soeren
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 111
Joined: Mon Aug 29, 2005 10:58 am
Location: Germany
Contact:

Re: How to output curly brackets - { } ?

Post by soeren » Mon Mar 06, 2006 8:14 pm

I think using HTML entities is no solution, because I need working Javascript code in the page.

This:

Code: Select all

if( !(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w&#123;2,4&#125;)+$/.test(form.email.value))) {
is no valid javascript.
I need another solution...

ciao, Soeren
Last edited by soeren on Tue Mar 07, 2006 8:34 am, edited 1 time in total.

User avatar
Vimes
Joomla! Ace
Joomla! Ace
Posts: 1675
Joined: Fri Aug 19, 2005 12:14 am
Location: United Kingdom
Contact:

Re: How to output curly brackets - { } ?

Post by Vimes » Mon Mar 06, 2006 10:29 pm

My apologies, I did say i hadn't looked properly at your question as I was just zipping passed.

I've had a dig around on the php tools website and can't find anything, however I recall that there used to be some patTemplate comment tags. If you put the above {2,4} between these comment tags, maybe that will get you around this little problem.
http://www.jomres.net THE online hotel booking and reservation system for Joomla and Wordpress.

User avatar
Vimes
Joomla! Ace
Joomla! Ace
Posts: 1675
Joined: Fri Aug 19, 2005 12:14 am
Location: United Kingdom
Contact:

Re: How to output curly brackets - { } ?

Post by Vimes » Tue Mar 07, 2006 1:55 am

Ok, done some more digging & while I can't find what I was referring to on the php tools site I did find it in some old code.

Try this:

{2,4}
http://www.jomres.net THE online hotel booking and reservation system for Joomla and Wordpress.

User avatar
ianmac
Joomla! Virtuoso
Joomla! Virtuoso
Posts: 4784
Joined: Sat Sep 24, 2005 11:01 pm
Location: Toronto, Canada

Re: How to output curly brackets - { } ?

Post by ianmac » Tue Mar 07, 2006 9:58 pm

But then it will be treated as a comment, will it not?  Which still won't output Javascript code with curly braces...  very interesting problem indeed...

Ian

User avatar
ianmac
Joomla! Virtuoso
Joomla! Virtuoso
Posts: 4784
Joined: Sat Sep 24, 2005 11:01 pm
Location: Toronto, Canada

Re: How to output curly brackets - { } ?

Post by ianmac » Tue Mar 07, 2006 10:17 pm

There is a discussion about this on the php-tools.net forum...  here is the link:

http://forum.php-tools.net/index.php?t= ... 60687f9d32

The suggestion is to escape the } {s using \...

YOu can escape them:

\{FOO\} should result in {FOO}

Haven't tested it though...

Ian

User avatar
Vimes
Joomla! Ace
Joomla! Ace
Posts: 1675
Joined: Fri Aug 19, 2005 12:14 am
Location: United Kingdom
Contact:

Re: How to output curly brackets - { } ?

Post by Vimes » Wed Mar 08, 2006 6:47 am

ianmac wrote: But then it will be treated as a comment, will it not?  Which still won't output Javascript code with curly braces...  very interesting problem indeed...

Ian
Oh pants, you're right.

Just looked at the forum post and it looks like it would do the job, but purely as an exercise I wonder if passing the value "{2,4}" in an array would have worked.
Last edited by Vimes on Wed Mar 08, 2006 6:50 am, edited 1 time in total.
http://www.jomres.net THE online hotel booking and reservation system for Joomla and Wordpress.

User avatar
Vimes
Joomla! Ace
Joomla! Ace
Posts: 1675
Joined: Fri Aug 19, 2005 12:14 am
Location: United Kingdom
Contact:

Re: How to output curly brackets - { } ?

Post by Vimes » Wed Mar 08, 2006 7:02 am

T'would appear not.
http://www.jomres.net THE online hotel booking and reservation system for Joomla and Wordpress.

User avatar
ianmac
Joomla! Virtuoso
Joomla! Virtuoso
Posts: 4784
Joined: Sat Sep 24, 2005 11:01 pm
Location: Toronto, Canada

Re: How to output curly brackets - { } ?

Post by ianmac » Thu Mar 09, 2006 10:14 pm

Try:

if( !(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(form.email.value))) {
}

Adding in the \ did seem to result in displaying the {, except for some reason the \ was left in... 

Ian

User avatar
soeren
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 111
Joined: Mon Aug 29, 2005 10:58 am
Location: Germany
Contact:

Re: How to output curly brackets - { } ?

Post by soeren » Thu Apr 06, 2006 1:48 pm

Hello,

thanks for you input Ian, but what is the point in your suggested code? It does not solve the problem.

Now as I'm testing VirtueMart on Joomla! 1.5 I've come across a lot of other issues caused by the same problem: patTemplate is greedy!
Why in the world patTemplate parses a section? Is that necessary at all? It just makes the Javascript unusable.

See this example, which is javascript code in the product listing in the VirtueMart admin:

BEFORE:

Code: Select all

function toggleDisable( elementOnChecked, elementDisable, disableOnChecked ) {
	try {
		//
	}
	catch( e ) { }
}
// another comment
AFTER THE BACKEND HAS BEEN PARSED IN JOOMLA 1.5:

Code: Select all

function toggleDisable( elementOnChecked, elementDisable, disableOnChecked ) {
	try {
		//
	}
	catch( e ) 
// another comment
Neither escaping the brackets with a backslash does help - nor using html entities.
I'm a bit puzzled about that.

Can anyone offer help on that?

ciao, Soeren

User avatar
soeren
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 111
Joined: Mon Aug 29, 2005 10:58 am
Location: Germany
Contact:

Re: How to output curly brackets - { } ?

Post by soeren » Tue Apr 18, 2006 10:27 am

Hello,

I'm asking this question once again:
soeren wrote: Why in the world patTemplate parses a section? Is that necessary at all? It just makes the Javascript unusable.
This is a serious problem. Please help me with this. The VirtueMart registration process will fail because of this problem.
Escaping the brackets with backslashes is not a solution.

thanks!

ciao, Soeren

davidrrm
Joomla! Explorer
Joomla! Explorer
Posts: 251
Joined: Mon Sep 05, 2005 3:50 pm

Re: How to output curly brackets - { } ?

Post by davidrrm » Mon May 01, 2006 5:29 pm

I don't know that you'd want to make a blanket decision not to parse inside of . There could be times when you'd want a substitution inside a script.

I think there are two ways around the problem currently -
You could change the start and end tags. I don't know if multi-character tags are allowed, but if so, you could use {{ }}.
Or, what if you make your section a template variable that you set? Does patTemplate run through the replaced items to find more variables?

It seems to me that if patTemplate finds a [starttag] [endtag] without a legal replacement variable inside it should just output that text and move on.

david

User avatar
soeren
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 111
Joined: Mon Aug 29, 2005 10:58 am
Location: Germany
Contact:

Re: How to output curly brackets - { } ?

Post by soeren » Mon May 01, 2006 8:02 pm

I'm not sure if you understand my situation. I'm trying to keep VirtueMart compatible to Joomla 1.0.x, Mambo and Joomla 1.5.
Joomla 1.5 uses patTemplate for ALL administration pages. Joomla 1.0.x does NOT.

That means I'll have to care for the product version and use two different version of a script. That's really not funny.
No, the main problem - and I consider this as a BUG - is that patTemplate breaks the javascript. And the only question for me is: why?

Please let me know the answer.

ciao, Soeren

User avatar
Vimes
Joomla! Ace
Joomla! Ace
Posts: 1675
Joined: Fri Aug 19, 2005 12:14 am
Location: United Kingdom
Contact:

Re: How to output curly brackets - { } ?

Post by Vimes » Mon May 01, 2006 9:20 pm

I have to admit, I'm a bit puzzled here. Is there a good reason to pass the javascript through patTemplate? Can't you just leave it in the template file(s)?
http://www.jomres.net THE online hotel booking and reservation system for Joomla and Wordpress.

davidrrm
Joomla! Explorer
Joomla! Explorer
Posts: 251
Joined: Mon Sep 05, 2005 3:50 pm

Re: How to output curly brackets - { } ?

Post by davidrrm » Mon May 01, 2006 11:35 pm

I haven't had a chance to look at 1.5 recently so I don't quite understand how patTemplates are working in the admin section. I'll have to take a look.

You could make your javascript a separate file and link it in. That shouldn't go through patTemplate.

david

User avatar
soeren
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 111
Joined: Mon Aug 29, 2005 10:58 am
Location: Germany
Contact:

Re: How to output curly brackets - { } ?

Post by soeren » Tue May 02, 2006 8:51 am

Hello,
thanks for your thoughts.
You could make your javascript a separate file and link it in.
That is ONE possible solution, but it doesn't handle onclick actions. Even onclick code is parsed by patTemplate and made unusable.
And: Sometimes one needs to assemble the Javascript by PHPright in the component's PHP file. Then you can't outsource the JS code easily into an external file. What to do then?

ciao, Soeren

User avatar
Vimes
Joomla! Ace
Joomla! Ace
Posts: 1675
Joined: Fri Aug 19, 2005 12:14 am
Location: United Kingdom
Contact:

Re: How to output curly brackets - { } ?

Post by Vimes » Wed May 03, 2006 2:43 am

soeren wrote: Sometimes one needs to assemble the Javascript by PHPright in the component's PHP file. Then you can't outsource the JS code easily into an external file. What to do then?
One of the ways I got around this problem was by dynamically building for loops, then eval'ing the results at template generation time.

Take a look at this: http://j2.jomres.net/ & click on the link to the component (I aint saying which one cos I'll get accused of self promotion ;) Just check my sig. )

If you visit the booking form via the Book a room link the optional extras and address panel are hidden divs before anything is clicked, however if you go to it via clicking a room's availability calendar  the panels are un-hidden. This is done by creating an array of the hidediv("yadda") then eval'ing those at template generation time, depending on prior conditions:

This is in the actual template file:

Code: Select all

var x
var toload=new Array()
<patTemplate:tmpl name="onload">toload[{COUNT}]= "{ONLOAD}" </patTemplate:tmpl>
And from the linked to javascript file:

Code: Select all

//onload function
function generic()
	{
	for (x in toload)
		{
		eval(toload[x]);
		}
	}
Of course, this isn't exactly what you're asking for, but maybe it'll help. My point is that it might be possible to have the required javascript permanently built into your linked to javascript file and simply define a set of triggers that are built at compile time of the template, eg if this user is not an administrator, checkThisInput = true, then onclick=validate(checkThisInput) and in the function if checkThisInput is true actually do the validation. It might sound long winded, but it works.

By the tone of your last post you sound tired and frustrated. Maybe you just need to leave it alone for a few days, come back when you're less fed up with it?

Just trying to help, good luck.
http://www.jomres.net THE online hotel booking and reservation system for Joomla and Wordpress.

User avatar
dorjano
Joomla! Explorer
Joomla! Explorer
Posts: 432
Joined: Tue Aug 30, 2005 11:26 am
Location: Slovenia
Contact:

Re: How to output curly brackets - { } ?

Post by dorjano » Mon May 22, 2006 10:49 pm

C'mon guys PLEASE help Soeren!!! He's working on a veeeeerrrrrryyy important piece of software  :-*

I'm preying for a solution Soeren, but as I said in a different topic without a good docs we are moving in a gray area :(
Moderator of Slovenian Forum

friesengeist
Joomla! Guru
Joomla! Guru
Posts: 842
Joined: Sat Sep 10, 2005 10:31 pm

Re: How to output curly brackets - { } ?

Post by friesengeist » Sat Jul 22, 2006 8:19 pm

Hi Sören, did you manage to solve this issue?

If not, here's an idea on how I managed to keep a comment (starting with '/*') in my output, although I had enabled the stripComments input modifier:

Code: Select all

<tmpl:var name="placeholder1" default="/* " />
Maybe using default="{" does work for you? (It might not work as your problem is not related to an input modifier).

Another option could be to include the parameter unusedvars="ignore" to your template (of course only if you have access to the template tag):

Code: Select all

<mos:tmpl name="somename" unusedvars="ignore">
 [...]
 </mos:tmpl>
I hope one of these options works for you...
Enno
We may not be able to control the wind, but we can always adjust our sails

User avatar
soeren
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 111
Joined: Mon Aug 29, 2005 10:58 am
Location: Germany
Contact:

Re: How to output curly brackets - { } ?

Post by soeren » Sat Jul 22, 2006 8:49 pm

Hi Enno,

thanks for getting back on this. Johan told me, that this patTemplate bug is solved in newer versions. It stripped out harmless Javascript (Again: The thing is that wherever you use HTML and inline Javascript and let it parse through patTemplate, patTemplate becomes greedy and strips out parts of the Javascript functions. This behaviour is not normal and should not require actions by the developer. Imagine a template developer who uses inline Javascript and wonders why his Javascript doesn't work after patTemplate has parsed it....).

In my case (some months ago) patTemplate changed

(\.\w{2,4})

to

(\.\w)

inside the script section.

You could do me a favor and test the javascript code I provided in the first message of this topic.
Put the code

Code: Select all

<script type="text/javascript">
//...
if( !(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(form.email.value))) {
   // ....
}
</script>
into a backend HTML file and display it. Is it the same as before?

ciao, Sören

friesengeist
Joomla! Guru
Joomla! Guru
Posts: 842
Joined: Sat Sep 10, 2005 10:31 pm

Re: How to output curly brackets - { } ?

Post by friesengeist » Sat Jul 22, 2006 11:11 pm

soeren wrote: Johan told me, that this patTemplate bug is solved in newer versions. It stripped out harmless Javascript (Again: The thing is that wherever you use HTML and inline Javascript and let it parse through patTemplate, patTemplate becomes greedy and strips out parts of the Javascript functions. This behaviour is not normal and should not require actions by the developer. Imagine a template developer who uses inline Javascript and wonders why his Javascript doesn't work after patTemplate has parsed it....).
Hm, I can understand that you consider this as a bug from your point of view. However, I think this is not really a bug, since it's a configurable behaviour of patTemplate. You can control it by changing the value of the "unusedvars" parameter of templates. The default value is set to "strip" to allow the use of variables that are not always initialised by php code (because they are empty in most cases and only have values when a user entered illegal data and the same form is shown again with the data he already entered).

I for my part always change the "unusedvars" parameter to "ingnore" for every template, so that I can see which variables are not initialized. Like that, I can also output brackets in JavaScript and so on. So the only "bug" that might be there in pT is IMHO the default value for "unusedvars", it probably should better be "ignore" than "strip".

http://php-tools.net/site.php?file=/pat ... c/tags.xml -> unusedvars
http://examples.php-tools.net/patTemplate/examples/ -> patTemplate::Attributes -> unusedvars (tmpl)
soeren wrote: You could do me a favor and test the javascript code I provided in the first message of this topic.
Put the code
[...]
into a backend HTML file and display it. Is it the same as before?
I've put it one of the com_mailto (frontend) templates. By default, the "variable" {2,4} is stripped out, as it was before.
It will be displayed (along with some other uninitialized vars) if you do this before you call $tmpl->displayParsedTemplate( 'form' ):

Code: Select all

$tmpl->setAttribute( 'body', 'unusedvars', 'ignore' );
 $tmpl->setAttribute( 'page', 'unusedvars', 'ignore' );
 $tmpl->setAttribute( 'form', 'unusedvars', 'ignore' );
 // $tmpl->setAttribute( [Maybe some more other templates in your case] , 'unusedvars', 'ignore' );
 $tmpl->displayParsedTemplate( 'form' );
Hope this helps ;-)
Enno
We may not be able to control the wind, but we can always adjust our sails

User avatar
soeren
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 111
Joined: Mon Aug 29, 2005 10:58 am
Location: Germany
Contact:

Re: How to output curly brackets - { } ?

Post by soeren » Sun Jul 23, 2006 9:49 am

Thanks for you help,

now this solution will work for patTemplate-enabled sites. Imagine a Joomla 1.0.x site where patTemplate is not used in the backend. The Javsacript will stay as it was before. In J! 1.5 it won't.
Is there a compatibility solution for inline Javascript with no PHP code at all? I'm having hard times with patTemplate.

ciao, Sören

wene
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 203
Joined: Sat Aug 20, 2005 1:40 am
Location: south of France

Re: How to output curly brackets - { } ?

Post by wene » Tue Jul 25, 2006 4:20 pm

hello
thats long time i havent play with PT, but i remember that there was some attributes to dont parse content like
parse=no
have you tried this ?

friesengeist
Joomla! Guru
Joomla! Guru
Posts: 842
Joined: Sat Sep 10, 2005 10:31 pm

Re: How to output curly brackets - { } ?

Post by friesengeist » Sun Jul 30, 2006 2:39 pm

soeren wrote: now this solution will work for patTemplate-enabled sites. Imagine a Joomla 1.0.x site where patTemplate is not used in the backend. The Javsacript will stay as it was before. In J! 1.5 it won't.
Is there a compatibility solution for inline Javascript with no PHP code at all? I'm having hard times with patTemplate.
Sorry for not getting back to this right away ;)

I thought you were talking about manually patTemplate-enabled components.
No, Joomla! does not strip any curly brackets from "normal" components anymore, no matter if you are inside a tag or not :) (Just tested with com_categories)

I guess this is good news for you?
We may not be able to control the wind, but we can always adjust our sails

User avatar
soeren
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 111
Joined: Mon Aug 29, 2005 10:58 am
Location: Germany
Contact:

Re: How to output curly brackets - { } ?

Post by soeren » Sun Jul 30, 2006 9:54 pm

...Joomla! does not strip any curly brackets from "normal" components anymore, no matter if you are inside a tag or not Smiley (Just tested with com_categories)

I guess this is good news for you?
Fantastic, thank you! These are good news indeed.
I will test it soon...

ciao, Soeren


Locked

Return to “patTemplate”