Author Topic: loop and include  (Read 1695 times)

0 Members and 1 Guest are viewing this topic.

Datoh

  • Guest
loop and include
on: Thu, 09. December 2004 - 17:41:51
Hi,

Good job for your vLIB tools.

I would like to know if it is possible to use an include in a loop?

Instead of:
<tmpl_loop name="loop1">
    <tmpl_var name=value /><br />
</tmpl_loop>


I would like in two file, test.thml:
<tmpl_loop name="loop1">
    <tmpl_include file="test_b.thtml" />
</tmpl_loop>

and test_b.thtml:
    <tmpl_var name=value /><br />

Thx,
Datoh.

Offline ClausVB

  • Administrator
  • Hero Member
  • *****
  • Posts: 566
    • Homepage: clausvb.de
loop and include
Reply #1 on: Thu, 09. December 2004 - 21:26:28
Should be possible. I see no reason, why it should not work.

Regards,
Claus

Datoh

  • Guest
loop and include
Reply #2 on: Thu, 09. December 2004 - 21:44:35
But, it doesnt work:)

The sub file (test_b.thtml) doesnt see that the var "value" come from a loop (newLoop(), addRow(), addLoop()).
It works fine if the var is a simple var (setVar() function).

Datoh

  • Guest
loop and include
Reply #3 on: Sun, 12. December 2004 - 00:28:09
I looked in the code and I saw you parse the include file to include the content in main template.
So I made a little modification, I add a preParseTag phase in _getData function:

Code: [Select]
regex1 = includes*;
                regex2 = var|if|elseif|else|endif|unless|endunless|loop|endloop|phpinclude|comment|endcomments*;
                regex1 = regex_head.regex1.regex_foot;
                regex2 = regex_head.regex2.regex_foot;
                
                data = preg_replaceregex1,this-_preParseTagarray0,1,2,3,4,5,6,7,8;,data;
                data = preg_replaceregex2,this-_parseTagarray0,1,2,3,4,5,6,7,8;,data;

_preParseTag
        function _preParseTag args {
            tag = strtolowerargs2;

            // arrange attributes
            for i=3; i 8; i=i+2 {
                if emptyargsi && emptyargsi+1 break;
                key = emptyargsi ? name strtolowerargsi;
                if key == name && preg_match/^php?include/, tag key = file;
                key = argsi+1;
            }

            // return correct string tag dependent
            switch tag {
                case include
                    file_name = this-_fileSearchfile;
     file_data = freadfp = fopenfile_name, r, filesizefile_name;
                 fclosefp;
                    return file_data;
                break;
            }
        }

You can find the complete vLibTemplate.php with test files here:
http://datoh.free.fr/vlib_datoh.zip

Regards,
Datoh.
Last Edit: Wed, 12. January 2005 - 15:32:43 by ClausVB