Author Topic: Something about TMPL_IF  (Read 1043 times)

0 Members and 1 Guest are viewing this topic.

Finn

  • Guest
Something about TMPL_IF
on: Wed, 25. September 2002 - 15:18:17
Downloaded vlibTemplate the other day and was convinced almost immediately - a wonderfull tool to seperate the html- and phpcode.

I've been playing around with it since and have only missed a few things.

The syntax for <TMPL_IF name="mybool"> comes short in some circumstances. If some menu (build by gifs) are included on all pages, and the selected function should show a different gif (to indicate what page/function is active), you have to use a vlib-var for each menuitem. If a syntax like <TPMP_IF name="somevar" value="somevalue"> was possible, this could be done by using only one var containing the name of the active page.

Besides this, thanx for a nice tool
Finn

releasedj

  • Guest
Something about TMPL_IF
Reply #1 on: Thu, 26. September 2002 - 09:52:54
There is a way around it, which should help give you an idea of how to use TMPL_IF in more efficient ways.

Let's say that you have a page variable ($page) which contains the details of the page that you're currently viewing, take a look at the following code:

Code: [Select]

?php

//.. first your php code and template instantiation

// $page can equal index, docs, examples or downloads

// you would write your setVar like this



if $page !== null

    $tmpl-setVar'page_'.$page, 1;





/*

Now, depending on which page is set, you'll have a var called

page_index, page_docs ... etc

*/

?


.. so your template would do something like:
Code: [Select]

.... text

tmpl_if name=page_index

    Home

tmpl_else

    a href=/index.phpHome/a

/tmpl_if

... etc



.. rest of your page



I hope this helps.
I have been thinking about an extended syntax for the TMPL_IF tags and your's is an interesting suggestion, I will think about it a little bit more however.

Kind regards,

Kelvin

Finn

  • Guest
Something about TMPL_IF
Reply #2 on: Thu, 26. September 2002 - 10:11:15
This is actually the way I've solved the problem.

But I still find that the html-template would look "nicer" if the template could use <tmpl_if name="page" value="index"> in the if-else sequence instead.

Anyway, it's only a language-construct suggestion.

Would it be ok for me to add this to the toolkit and mail you the patch?

Which other ideas for extending the syntax for if's have you been considering?

Kind regards
Finn

releasedj

  • Guest
Something about TMPL_IF
Reply #3 on: Thu, 26. September 2002 - 10:30:23
Please feel free to edit the source.

I definately think that extending the TMPL_IF would be useful, but I've been undecided about how far the extended syntax should go.
vlibTemplate's aim is to be user friendly, especially on the template side, so that designers can use it with ease.
This is one reason that I like your suggestion, it's simple.
But, I was thinking about possibly giving the possibility of defining the operator for the comparison, ie:
Code: [Select]
tmpl_if name=varname op== value=20

What do you think?
Perhaps this would over-complicate things!

Kelvin

Finn

  • Guest
Something about TMPL_IF
Reply #4 on: Thu, 26. September 2002 - 11:01:47
If the operator would be optional and default to "==" I certainly think it's a good idea.

Even though I cannot (now) think of any places where I would use other operators than "==", others might find it usefull - and I might tomorrow  :)

I'll look into the source later and see if I can make the needed correction.

Kind regards
Finn

releasedj

  • Guest
Something about TMPL_IF
Reply #5 on: Thu, 26. September 2002 - 14:44:13
Well, I think some people might use other operators such as ">=" in a loop.
I'm, sure that  people would find it useful, and thinking about it, I don't think it would complicate things to much as it's all completely optional.

K