difference between "src" and "call" to display values

A general technical discussion area for patTemplate.
Locked
wene
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 203
Joined: Sat Aug 20, 2005 1:40 am
Location: south of France

difference between "src" and "call" to display values

Post by wene » Sun Oct 30, 2005 3:41 am

hello
i would like to re-use templates, so i have played with the "call" function.
but when i use this, i can see that the datas are not displayed in my niew template.

i can see the good values inside the dump(), but they dont appear inside the one i called.

when i use src, the values appear, but i cant repeat the template because already loaded.

how to render my values with "call" function ?
Last edited by wene on Sun Dec 25, 2005 4:20 am, edited 1 time in total.

alwarren
Joomla! Guru
Joomla! Guru
Posts: 527
Joined: Fri Aug 19, 2005 9:27 am

Re: difference between "src" and "call" to display values

Post by alwarren » Sun Oct 30, 2005 8:11 am

Try using "unusedvars = ignore" in your called template. Has something to do with the order things are parsed. Not sure I understand it but it works for me.

Code: Select all

Php: $tmpl->addVar('tempname', 'varname', '$value');

Calling template:
<mos:tmpl name="tempname">
	<mos:Call template="temp2name" varname="{VARNAME}">
<mos:/tmpl>

Called template:
<mos:tmpl name="temp2name" unusedvars="ignore">
	<div>{VARNAME}</div>
</mos:tmpl>
Also if you have your called templates in a separate file, you must read them first.

Code: Select all

$tmpl->readTemplatesFromInput( 'called.tmpl' );
$tmpl->readTemplatesFromInput( 'calling.tmpl' );
On a side note. I've disovered that in most cases the "varname={VARNAME}" isn't needed. In some examples I've seen it's used. I wound up removing it from all my calling templates. Might have something to do with varscope. Not sure. Still in the learning curve here.
Al Warren
This ain't my first rodeo. Red Foreman says it best.
CQDX de WR5AW

wene
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 203
Joined: Sat Aug 20, 2005 1:40 am
Location: south of France

Re: difference between "src" and "call" to display values

Post by wene » Sun Oct 30, 2005 4:52 pm

--edit--
this simplified example didnt give me the same result than my prog, so i modified the php code to get the same result.
it is funny, that it loads the values only when i create a function...
i can also do :
function justreturn ($tmpl){
    return $tmpl;
    }
$tmpl =& justreturn($tmpl);
$tmpl -> addVar ( 'test', 'testvar', 'hello' );
it works the same ... but my prob is not solved
--/edit--


php job :

Code: Select all

<?php
//--- i create the patTemplate object and read the needed template
    require_once( $mosConfig_absolute_path . '/includes/patTemplate/patTemplate.php' );
    $tmpl =& patFactory::createTemplate( '', false, false );
    $tmpl->setRoot( dirname( __FILE__ ) . '/tmpl' );

//--- i read the desired called template.
    $tmpl->readTemplatesFromFile( 'test.html' );

//--- i give a value to the desired var
// to get the same result than my program, i had to build a function.
    function feedVar ($tmpl){
        $tmpl -> addVar ( 'test', 'testvar', 'hello' );
        return $tmpl;
    }
    $tmpl = & feedVar($tmpl);
    
//--- i read and display the "master" template
    $tmpl->readTemplatesFromFile( 'master.html' );
    $tmpl->displayParsedTemplate( 'master' );
?>
master.html :

Code: Select all

<mos:tmpl name="master">
    test=<mos:call template="test"/> 
    test2=<mos:call template="test"/> 
    test3=<mos:call template="test"/>
</mos:tmpl>
test.html :

Code: Select all

<mos:tmpl name="test">
    {TESTVAR}
<mos:tmpl>
when i render this, i can see that the variable has got the good value in the dump() window.
like this:


Template "test"
Variables
Name        Assigned Value      Modifier

TESTVAR    hello                    [none]

i can not see the "hello" in the master template.
in my output, i see :
test= test2= test3=
and i would like to see:
test=hello test2=hello test3=hello

i can see the good value when i use "src" instead of "call" but, in this case, i cant repeat the template.
Last edited by wene on Sun Oct 30, 2005 6:15 pm, edited 1 time in total.

wene
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 203
Joined: Sat Aug 20, 2005 1:40 am
Location: south of France

[solved] Re: difference between "src" and "call" to display values

Post by wene » Sun Oct 30, 2005 6:30 pm

It works !!!
thank you Alwarren !!
i have used unusedvars="ignore" on the test template like this :

Code: Select all

<mos:tmpl name="test" unusedvars="ignore">
    {TESTVAR}
<mos:tmpl>
then , i had to assign the value to the master template like this :

Code: Select all

$tmpl -> addVar ( 'master', 'testvar', 'hello' );
and not like :

Code: Select all

$tmpl -> addVar ( 'test', 'testvar', 'hello' );
this is exactly what iam dreaming about for 2 days... :)


Locked

Return to “patTemplate”