Foren / Cotonti / Core Labs / Archive / Logic blocks for xtemplate

12NächsteLetzte

medar
#1 9. März 2009, 22:59
New xtemplate.class.php: http://www.cotonti.com/datas/users/xtemplate.class_45.rar
Added logic blocks and some improve of code.

Logic blocks:
<!-- IF <if_statement> -->
this will display if <if_statement> is true
<!-- ENDIF -->
in <if_statement> allowed all avaiable tpl-tags !

Examples:
<!-- IF {PHP.usr.profile.user_name} == "admin" -->
hello admin !
<!-- ENDIF -->

<!-- IF {PAGE_DESC}=="" -->
Description of this page is empty
<!-- ENDIF -->

<!-- IF {PAGE_DESC}=={PAGE_TITLE} AND {PAGE_COMMENTS_COUNT} > 0 -->
There is some comments here.
And title and description of this page are equal.
<!-- ENDIF -->

Benchmark:
CentOS 5, Apache 2, php 5.2.8
Testing:
ab -c 4 -n1000 "http://exampler.net/cotonti/page.php?id=2"

Old xtemplate
Requests per second: 16.30 [#/sec] (mean)

New xtemplate, tpl without IF
Requests per second: 17.47 [#/sec] (mean)

New xtemplate, tpl with 1 IF
Requests per second: 16.78 [#/sec] (mean)

New xtemplate, tpl with 25 IF
Requests per second: 15.60 [#/sec] (mean)

Please test, comment and i will commit it.
rangjungyeshe.ru
Orkan
#2 10. März 2009, 17:01
This reminds me all kind of discussion over the net about putting logic in CSS files, like macros, expressions, etc...
Programmers say Yes! but for CG artists this will be way too much complicated... and who will make templates then?
Problem is deeper than these IF/ENDIF improvements.
Logic should stay away from presentation, IMO

One would say "If you dont like it, then dont use it" but what if an artist makes changes in someone else work an there are plenty of "logic" inside?
Perl - the only language that looks the same before and after RSA encryption.

Dieser Beitrag wurde von Orkan (am 10. März 2009, 17:07, vor 15 Jahre) bearbeitet
medar
#3 10. März 2009, 17:40
I don't understand why all praying on "Logic should stay away from presentation"

Simple example.
There in field users_photo with url of picture. It need display in user page.

<img src="{USERS_PHOTO}" /> is bad solution - if users_photo is empty IE will display error empty image.
Admin must write plugin for tag {SHOW_USERS_PHOTO}
Admin must
- know PHP
- know Cotonti plugin system

But now admin write in tpl:
<!-- IF {USERS_PHOTO}!="" -->
<img src="{USERS_PHOTO}" />
<!-- ENDIF -->

And no problem!
Logic blocks - for similar simple solutions. For complex need to write plugin fo course.

BTW, request on this feature i was get from skinmaker, not programmer.
Orkan:
One would say "If you dont like it, then dont use it" but what if an artist makes changes in someone else work an there are plenty of "logic" inside?
If artist understand english, he will understand logic blocks. :)
rangjungyeshe.ru

Dieser Beitrag wurde von medar (am 10. März 2009, 17:51, vor 15 Jahre) bearbeitet
musiconly
#4 10. März 2009, 18:16
I actually like this logic bloks, from the designers perspective..

<!-- IF {PAGE_OWNER}=={COMMENTS_ROW_AUTHORID} -->
<div style="background-color: #c3c3c3;"> (rest of code here) </div>
<!-- ENDIF -->

So basically, if comment author is also the page owner, his comment will stand out from the other comments by changing color of background etc.

Also one more example:

<!-- IF {PHP.usr.profile.user_logcount} < '5' -->
Hello {PHP.usr.profile.user_name}! We noticed that you are new here,
 so please take a look at our <a hre="">Rules</a> and <a href="">FAQ</a> 
to save your time while waiting for an already answered question!
<!-- ENDIF -->

This is great! :-)
Lombi
#5 10. März 2009, 19:55
+1 for logic blocks! Sounds like awesome things can be done with them...
<a href="http://www.domenlo.com">Surreal Art</a>
Brock
#6 11. März 2009, 08:07
Agreed. It would be probably one of the best additions ever made to Cotonti from my standpoint.
Web Design Database - www.wddb.com
Kilandor
#7 11. März 2009, 14:46
It will require some testing. I see some circumstances it could be a cheap dirty way to do things.

If its put in the core, I don't think any core skin files should use it.

No images in the core should be output anyways, causing red-square issues with IE, if they don't exist.

And it still requires some knowledge of php to use essentially it looks like, or atleast if statment knowledge. So its something a plugin can do anyways.

I'm guessing also it would require more parsing time, due to it has to look for code it has to execute, and if someone bloated their page with "logic" blocks it could cause longer executions

I totaly agree with Orkan, logic should stay away from the HTML, thats the whole point of using a template engine. Otherwise we could just do the stupid stuff you see in other CMS's and crappy PHP programming using <?php echo "blah"; ?> in our files.

I know this is an example, but I see it uses Eval which could be potentially bad, If a admin used a If that some how came from userinput it could leave the possiblity for arbitrary php execution by a user, allowing them to do anything they wish.

It would need to be a restricted enviroment something like sed_url

Dieser Beitrag wurde von Kilandor (am 11. März 2009, 15:11, vor 15 Jahre) bearbeitet
tensh
#8 11. März 2009, 17:43
Yes, yes, yes!!!
This is what I was waiting for :D

As for template engines... the most popular template engines use logic statements in their code... I don't want to argue if it's right or not, but that's the way it is.

The don't have to be used by everybody anyway, but they give extra flexibility and ease of customizations.

I also would say that "logic" apply to design as well. If you put something responsible for design part into plugins, would it be the other way round? Putting design where only programming should be? (It's the case with Leetlogin plugin, I had problems modifying it to suit various skins, it had html hardcoded into it.)

EDIT: Well, if you prefer, you can merge the "plugin versus template core" doubts and make a plugin that is an extension of template engine... or can it be done?

Dieser Beitrag wurde von tensh (am 11. März 2009, 19:07, vor 15 Jahre) bearbeitet
Trustmaster
#9 14. März 2009, 22:29
Generally, I'd like to keep templates clear and simple, so I don't like the overcomplicated templates like Smarty.

But these simple conditional blocks is minimimal measure to make the templates by far more flexible.

However, looking through the XTemplate code once again (I already did an investigation before, you can find results on Neocome in a topic called "Searching for a bottle neck"), I came to a conclusion that it is horribly coded. And we should thank god and PCRE author that it doesn't slow everything down too much.

I doubt we can switch to any other template engine for two reasons: a) compatiblity with existing skins; b) XTemplate is one of the best block-style template engines from the usability point of view available on the net. But as soon as we have time for the task, XTemplate should be reengineered, keeping existing interface and behavior but using CPU time and RAM more efficiently.

What I would like to see in this topic, is some opinions from our designers and skin makers about how comfortable this IF sequence is for them and how it could be improved by being more usable/easy for them.
May the Source be with you!

Dieser Beitrag wurde von Trustmaster (am 14. März 2009, 22:33, vor 15 Jahre) bearbeitet
Brock
#10 15. März 2009, 05:47
I think that if it is well documented, then no one would have a problem with using them. As people've already said, the logic blocks are optional. I think the flexibility that is able to be accomplished by this addition would be able to take Cotonti to the next level. User id / group checks would be made even easier, as it's done souly in the template files. That makes you not have to have a separate plugin for basic tasks like you do now.

Also, it helps plugin functionality, and gives the standard users the ability to customize their plugin even more. As long as they can grasp the logic block methods, they will be able to easily edit the TPL file of the plugin to do what they need it do.

I think this is one of the best ideas, and I surely hope that it is integrated.
Web Design Database - www.wddb.com
GHengeveld
#11 17. Juni 2009, 06:48
I think the suggested way of using IF/ELSE statements is great. I've been missing this for a long time. My main use would be in tables, for example users.details.tpl. There's no use in displaying a table row if its value isn't set. It's much nicer to just leave out the entire row. It will just make things much much cleaner in the end and will prevent having to write lots of code for a plugin.

I say go for it!
Elgan
#12 18. Juni 2009, 02:06
ive always wanted this and also went through all the xtemplate stuff in seditio a while bk. It was all hectic and not worth it with all new 125 coming out, I also cant and dont have time to skin and just did it all via php.

It would be a good tool but used v.limited. like the tables thing. Most can be done via php directly from the plugin.

I always thought it would be nice to be able to callback, like the same as having a list of what tags are in the skin, so can skip extra work load getting info for a non existing tag. It is also all v.nice keeping it nice and simple. Tho a if tag thing could be good somehow if its worth it.
tensh
#13 23. Juni 2009, 19:40
What "if statement" would you build to check whether user is logged in? Preferably hearer or global tag. I'm thinking of the Tag to be used...

Got it:

<!-- IF {PHP.usr.profile.user_maingrp} > "4" -->   <!-- ENDIF -->

Dieser Beitrag wurde von tensh (am 23. Juni 2009, 19:47, vor 14 Jahre) bearbeitet
KillerSneak
#14 20. Juli 2009, 19:42
# tensh : What "if statement" would you build to check whether user is logged in? Preferably hearer or global tag. I'm thinking of the Tag to be used...

Got it:

<!-- IF {PHP.usr.profile.user_maingrp} > "4" -->   <!-- ENDIF -->
Can this be used for whole DIV blocks?

http://www.donotargue.com/

You can see some Advertisement blocks on my site. I would like them not to show for my Donators but the code above doesn't seem to work to hide:


	<div class="lboxHD">Advertisement :</div>
	<div class="lboxBody"><center>
        <script type="text/javascript"><!--
	google_ad_client = "pub-*******************";
	/* dna50blue_index_468x60, gemaakt **-**-** */
	google_ad_slot = "*********";
	google_ad_width = ***;
	google_ad_height = **;
	//-->
	</script>
	<script type="text/javascript"
	src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
	</script>
	</center></div>

Putting the above between
<!-- IF {PHP.usr.profile.user_maingrp} > "17" -->   
<!-- ENDIF -->

Doesn't work?:

EDIT:
Running COTONTI 0.0.5 as i don't like the 547328957483257 new TPL tags in 0.0.6
Trustmaster
#15 20. Juli 2009, 21:04
There are no logic blocks in 0.0.5. In 0.0.6
<!-- IF {PHP.usr.profile.user_maingrp} > 17 -->   
<!-- ENDIF -->
would work. And if you read carefully, all those 547328957483257 TPL tags are Admin area. Which had to be templated somewhen like it or not. Sorry for being that rude to you.
May the Source be with you!

12NächsteLetzte