Author Topic: Problem tmpl_if  (Read 2271 times)

0 Members and 2 Guests are viewing this topic.

Emanuele

  • Guest
Problem tmpl_if
on: Thu, 18. January 2007 - 18:56:57
Hello, excuse my English…. I have a problem with tmpl_id of vlib

this is the code php of the query
Code: [Select]
$categorie_padre = array();
$categoria_padre = $connetti->query("SELECT * FROM ".$blog_tbl[tbl_blog_categoria]." WHERE cat_parent_id = 0 ");
while($array = $connetti->fetchArray($categoria_padre)){
//echo"<div class=\"right_articles\"><a href=\"?cat=$array[cat_id]\"><strong>$array[cat_nome]</strong></a></div>" ;

$categoria_figlio = $connetti->query("SELECT * FROM ".$blog_tbl[tbl_blog_categoria]." WHERE cat_parent_id = $array[cat_id]");
while($array2 = $connetti->fetchArray($categoria_figlio)){
if($array2[cat_parent_id]==$_GET[cat])
//echo"<div class=\"right_articles\">- <a href=\"sottocategorie.php?sottocat=$array2[id]&id=$array[id]\">$array2[cat_nome]</a></div>" ;
$cat_parent = $array2[cat_nome];
$cat_parent_id = $array2[cat_parent_id];
$cat_id2 = $array2[cat_id];
$cat = $_GET[cat];
}
array_push($categorie_padre, array(
cat_id => $array[cat_id],
cat_id2 => $cat_id2,
cat_nome => $array[cat_nome],
cat_parent_nome => $cat_parent,
cat_parent_id => $cat_parent_id ,
cat => $cat
));
$tmpl->setloop(categorie, $categorie_padre);
}

Code: [Select]
<tmpl_if name=cat_parent_id op=== value=cat>
{tmpl_var name=cat_parent_nome}
</tmpl_if>


but it does not work….
I want when cat_parent_id he is equal to cat ($_GET [cat])

it visualized the name of under category pertaining to cat :(

Thanks

Offline ClausVB

  • Administrator
  • Hero Member
  • *****
  • Posts: 566
    • Homepage: clausvb.de
Re: Problem tmpl_if
Reply #1 on: Fri, 19. January 2007 - 09:43:20
This ist not possible. You have to compare these values in PHP not in your template.

A short example:
Code: [Select]
<?php
$access_level 
get_access_level($_SERVER[PHP_AUTH_USER], $user_id);
if (
$access_level == $admin_level)
{
// if in aclev == admin_level the template will output the admin-links
  
$tmpl->setVar(admin1); 
}
?>

Code: [Select]
<tmpl_if name=admin> <!-- admin links -->
(...)
<tmpl_else> <!-- user links -->
(...)
</tmpl_if>

It is not possible to compare variables with TMPL_IF. TMPL_IF can compare one variable with a constant like: "1", "97", "admin", "user". Comparing two variables is not possible.

Regards,
Claus

Emanuele

  • Guest
Re: Problem tmpl_if
Reply #2 on: Fri, 19. January 2007 - 11:35:42
I understand, however the example is much profit

   
for my problem I will resolve directly inserting the code php in the template ones. Thanks

Code: [Select]
$dati = mysql_query("SELECT * FROM tbl_blog_categoria WHERE cat_parent_id = 0 ORDER BY cat_nome");
while($array = mysql_fetch_array($dati)){
echo"<a href=\"?azione=categorie&cat_id=$array[cat_id]\">$array[cat_nome]</a><br>";   

 $dati2=mysql_query("SELECT * FROM tbl_blog_categoria WHERE cat_parent_id = $array[cat_id]");
 while($array2 = mysql_fetch_array($dati2)){
  if($array2[cat_parent_id]==$_GET[cat_id])   
 echo"- <a href=\"?azione=categorie&cat_id=$array[cat_id]&categoria=post&parent_id=$array2[cat_id]\">$array2[cat_nome]</a><br>" ;
}
}

Offline ClausVB

  • Administrator
  • Hero Member
  • *****
  • Posts: 566
    • Homepage: clausvb.de
Re: Problem tmpl_if
Reply #3 on: Fri, 19. January 2007 - 12:52:01
Please dont do that. PHP code is not allowed in templates. It is a bug within vLIB and will be deactivated in the next version.

vlibTemplate ist to seperate PHP and HTML. So your application will not work with the next release.

It is wrong to even try to mix PHP and HTML with vlibTemplate.

Regards,
Claus

Emanuele

  • Guest
Re: Problem tmpl_if
Reply #4 on: Thu, 25. January 2007 - 00:10:59
Please dont do that. PHP code is not allowed in templates. It is a bug within vLIB and will be deactivated in the next version.

vlibTemplate ist to seperate PHP and HTML. So your application will not work with the next release.

It is wrong to even try to mix PHP and HTML with vlibTemplate.

Regards,
Claus

I have inserted in this way in my template ones
<? php it includes (“categorie.php”); >
and it works without problems…. it was the only solution.

Why it does not allow to inside introduce code php of the template ones?

this is much profit
Last Edit: Thu, 25. January 2007 - 00:14:30 by Emanuele

Offline ClausVB

  • Administrator
  • Hero Member
  • *****
  • Posts: 566
    • Homepage: clausvb.de
Re: Problem tmpl_if
Reply #5 on: Thu, 25. January 2007 - 17:31:31
and it works without problems…. it was the only solution.

No, it is not. See
http://lamp.clausvb.de/vlib_examples/modular_php_require.php
or
http://lamp.clausvb.de/vlib_examples/modular_tmpl_include.php
how you can handle navigation, categories and so on.

You are able to program superb modules like:
- head
- navigation_top
- navigation_left
- content
- footer
with vLIB and you will not have to mix PHP and HTML.


Quote
Why it does not allow to inside introduce code php of the template ones?

Because using a template engine means: "I do not want to mix HTML and PHP". If you want to do that, you can use PHP and HTML in one file. You wont need vLIB or Smarty or TinyButStrong or ANY template engine.

You can use something like this

Code: [Select]
<table> 
   <tr> 
       <th>Id</th> 
       <th>Name</th> 
       <th>Email</th> 
       <th>Banned</th> 
   </tr> 
<? foreach($user_list as $user): ?> 
   <tr> 
       <td align="center"><?=$user[id];?></td> 
       <td><?=$user[name];?></td> 
       <td><a href="mailto:<?=$user[email];?>"><?=$user[email];?></a></td> 
       <td align="center"><?=($user[banned] ? X : &nbsp;);?></td> 
   </tr> 
<? endforeach; ?> 
</table>
(Source: Beyond The Template Engine by Brian Lozier)

to seperate most PHP from HTML, but you do not have a complete template engine, which is able to support WYSIWYG and SETDBLOOP (parsing content from a database to the template).



Your scripts will not work with vLIB_4-1-0 and you will have to stick to your old vLIB version.

Mixing PHP and HTML is against any goal, vLIB stands for, so it will not be supported any longer.

Regards,
Claus
Last Edit: Thu, 25. January 2007 - 17:35:25 by ClausVB

Emanuele

  • Guest
Re: Problem tmpl_if
Reply #6 on: Thu, 25. January 2007 - 20:54:37
I understand has been much luminosity.
But Smarty comes defined one of the template better engine, but to me it does not appeal to. vLIB it has many functions that a lot as an example setdbloop he is exceptional saves much time and code.

   
we return to we…. I in my plan it is multilanguage therefore I have defined some names types
example

define (MENU, Menu );
define (MENU_2, Moduli );

as I can use in the template ones with vLIB, I must create an Array?
example writes please....

at last last thing I have not understood well like including categorie.php in the temaplate ones without to write code php of it inside

this is possible?

$tmpl->setvar(categorie, categorie.php);

Tnx

Offline ClausVB

  • Administrator
  • Hero Member
  • *****
  • Posts: 566
    • Homepage: clausvb.de
Re: Problem tmpl_if
Reply #7 on: Thu, 25. January 2007 - 21:13:52
as I can use in the template ones with vLIB, I must create an Array?
example writes please....

I have posted examples, as you can see above. Please explain to me, what you do not understand and ask specific questions. Thanks!

If you need it:
Example, how to use TMPL_IF in a LOOP

You should take a look at
Navigation with vLIB
Which is better: REQUIRE_ONCE or TMPL_INCLUDE?

Regards,
Claus
Last Edit: Thu, 25. January 2007 - 21:25:46 by ClausVB

Emanuele

  • Guest
Re: Problem tmpl_if
Reply #8 on: Fri, 26. January 2007 - 00:35:35
Thanks thousand ClausVB , use the previous version I find myself well  ;)

Offline ClausVB

  • Administrator
  • Hero Member
  • *****
  • Posts: 566
    • Homepage: clausvb.de
Re: Problem tmpl_if
Reply #9 on: Fri, 26. January 2007 - 15:15:57
Perfect!

Regards,
Claus