cotonti.com : Logic blocks for xtemplate https://www.cotonti.com Последние сообщения в теме Cotonti en Tue, 16 Dec 2025 04:15:03 -0000 Kilandor пт, 02 окт 2009 18:53:34 -0000 tensh http://www.cotonti.com/plug.php?e=tpltags - here are other ones... but not global.]]> пт, 02 окт 2009 18:47:14 -0000 GHengeveld ср, 30 сен 2009 20:30:38 -0000 Trustmaster ср, 30 сен 2009 15:57:41 -0000 GHengeveld 988 / 989 you can use two new operators, namely HAS and CONTAINS. These can be used to access the PHP functions array_search() and strpos() respectively.

Examples:
<!-- IF {PHP.usr.name} CONTAINS 'test' -->
Your nickname contains the phrase 'test' !
<!-- ENDIF -->

The second example could be used in conjunction with a plugin listing your user subgroups in an array, something like this:
<!-- IF {PHP.subgroups} HAS 'moderators' -->
You are a member of the 'moderators' user group.
<!-- ENDIF -->

UPDATE: I realized that array_search() would be more practical so I updated the HAS operator to use that instead of in_array(). This will make sure it checks the values, not the keys.]]>
ср, 30 сен 2009 05:25:20 -0000
Trustmaster пн, 20 июл 2009 22:05:07 -0000 KillerSneak 0.0.6 but can't during workign days (making 12 hour shifts because of the vacation perioud) If before this weekend nobody has a TUT i will write down the changes i have made with the templates and post my findings. Thanks for your clear and fast responce Trustmaster.]]> пн, 20 июл 2009 22:00:53 -0000 Trustmaster
I know it's hard to change the templates (because I did it for this site, which was actually running 0.0.4 before). We thought tpltags listing would help, but it is confusing you with all those ADMIN tags, which are really new and had to emerge somewhen. As for the rest, most of all tags are left untouched. The only valuable changes are about the Submit button in page.add.tpl and page.edit.tpl and the PM templates that were split into list and display/reply. An article/tutorial about updating skins would be helpful, but there isn't anybody who has done it in his spare time so far. So, if someone did, we would be very grateful.]]>
пн, 20 июл 2009 21:43:31 -0000
KillerSneak # Trustmaster : 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.
Your not rude (as one of few the admins/dev's) just couldn't find anywhere in this topic/forum on what version / system it works. And I'm against TAGS adding no matter what CMS as it's a pain in the ass (most of the time) to redo already modded templates. So this only works starting with 0.0.6? (just to be clear)]]>
пн, 20 июл 2009 21:15:17 -0000
Trustmaster
<!-- 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.]]>
пн, 20 июл 2009 21:04:52 -0000
KillerSneak # 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=https://www.cotonti.com/"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]]>
пн, 20 июл 2009 19:42:23 -0000
tensh
Got it:

<!-- IF {PHP.usr.profile.user_maingrp} > "4" -->   <!-- ENDIF -->
]]>
вт, 23 июн 2009 19:40:19 -0000
Elgan
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.]]>
чт, 18 июн 2009 02:06:26 -0000
GHengeveld
I say go for it!]]>
ср, 17 июн 2009 06:48:17 -0000
Brock
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.]]>
вс, 15 мар 2009 05:47:32 -0000
Trustmaster
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.]]>
сб, 14 мар 2009 22:29:20 -0000
tensh 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?]]>
ср, 11 мар 2009 17:43:31 -0000
Kilandor
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]]>
ср, 11 мар 2009 14:46:36 -0000
Brock ср, 11 мар 2009 08:07:49 -0000 Lombi вт, 10 мар 2009 19:55:04 -0000 musiconly
<!-- 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=https://www.cotonti.com/"">FAQ</a> 
to save your time while waiting for an already answered question!
<!-- ENDIF -->

This is great! :-)]]>
вт, 10 мар 2009 18:16:34 -0000
medar
Simple example.
There in field users_photo with url of picture. It need display in user page.

<img src=https://www.cotonti.com/"{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=https://www.cotonti.com/"{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. :)]]>
вт, 10 мар 2009 17:40:21 -0000
Orkan 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?]]>
вт, 10 мар 2009 17:01:07 -0000
medar 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.]]>
пн, 09 мар 2009 22:59:06 -0000