how to get rows from another tmpl ?

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

how to get rows from another tmpl ?

Post by wene » Fri Dec 09, 2005 5:38 pm

hello

how to get rows from another template ?

i need to do something like this :

php :

Code: Select all

$rows = database->loadObjectList();
$tmpl-> addGlobalVar ("canedit",1);
$tmpl-> addObject( "my-tmpl", $rows, 'row_' );
html :

Code: Select all

<mos:tmpl name="my-tmpl-canedit-test" type="condition" conditionvar="canedit" useglobals="yes">
    <mos:sub condition="__default">
        <ul>
        <mos:tmpl name="my-tmpl">
            <li>
                {ROW_TEST}
            </li>
        </mos:tmpl>
        </ul>
    </mos:sub>
    <mos:sub condition="1">
        <ul>
        <mos:tmpl name="my-tmpl-readonly" varscope="my-tmpl">
            <li>
                {ROW_TEST}
            </li>
        </mos:tmpl>
        </ul>
    </mos:sub>
</mos:tmpl>
but when canedit !=1,  it returns me only the first row +
Notice: Undefined index: loop in ......\includes\patTemplate\patTemplate.php on line 2181

so i do like this :

php :

Code: Select all

$rows = database->loadObjectList();
$canEdit = 1;
$tmpl-> addGlobalVar ("canedit",$canEdit);
$my_tmpl = "my-tmpl";
if ($canEdit !=1){
    $my_tmpl = "my-tmpl-readonly";
$tmpl-> addObject( $my_tmpl, $rows, 'row_' );
html :

Code: Select all

<mos:tmpl name="my-tmpl-canedit-test" type="condition" conditionvar="canedit" useglobals="yes">
    <mos:sub condition="__default">
        <ul>
        <mos:tmpl name="my-tmpl">
            <li>
                {ROW_TEST}
            </li>
        </mos:tmpl>
        </ul>
    </mos:sub>
    <mos:sub condition="1">
        <ul>
        <mos:tmpl name="my-tmpl-readonly">
            <li>
                {ROW_TEST}
            </li>
        </mos:tmpl>
        </ul>
    </mos:sub>
</mos:tmpl>
but sometimes, i need to do things like this :

html :

Code: Select all

<ul>
<mos:tmpl name="my-tmpl">
    <li>
        {ROW_TEST}
    </li>
</mos:tmpl>
</ul>
<mos:tmpl name"my-tmpl2">
    blah blah... {ROW_TEST}
</mos:tmpl>
<mos:tmpl name"my-tmpl3">
    sdfgsdfgsldjhgdsflghsdufighoeihg... {ROW_TEST}
</mos:tmpl>
i would like to use the "varscope" attribute, but i cant make it work.
so i do this :

php :

Code: Select all

$rows = database->loadObjectList();
$tmpl-> addObject( "my-tmpl", $rows, 'row_' );
$tmpl-> addObject( "my-tmpl2", $rows, 'row_' );
$tmpl-> addObject( "my-tmpl3", $rows, 'row_' );
.......that is not beautifull at all...

i have tried this too :

php :

Code: Select all

$rows = database->loadObjectList();
$tmpl-> addObject( "my-tmpl", $rows, 'row_' );
html :

Code: Select all

<mos:tmpl name="my-tmpl"></mos:tmpl>
<ul>
<mos:tmpl name="my-tmpl1" varscope="my-tmpl">
    <li>
        {ROW_TEST}
    </li>
</mos:tmpl>
</ul>
<mos:tmpl name"my-tmpl2" varscope="my-tmpl">
    blah blah... {ROW_TEST}
</mos:tmpl>
<mos:tmpl name"my-tmpl3" varscope="my-tmpl">
    sdfgsdfgsldjhgdsflghsdufighoeihg... {ROW_TEST}
</mos:tmpl>
but i dont think that its a good solution...
Last edited by wene on Sun Dec 25, 2005 4:21 am, edited 1 time in total.

User avatar
masterchief
Joomla! Hero
Joomla! Hero
Posts: 2316
Joined: Fri Aug 12, 2005 2:45 am
Location: Brisbane, Australia
Contact:

Re: how to get rows from another tmpl ?

Post by masterchief » Fri Dec 09, 2005 10:01 pm

I think you will have to do something like your

Code: Select all

$tmpl-> addObject( "my-tmpl", $rows, 'row_' );
$tmpl-> addObject( "my-tmpl2", $rows, 'row_' );
$tmpl-> addObject( "my-tmpl3", $rows, 'row_' );
case.

Can you give me an example of the 'real' output for canedit = 0 or 1

Thanks.
Andrew Eddie - Tweet @AndrewEddie
<><
http://eddify.me
http://www.kiva.org/team/joomla - Got Joomla for free? Pay it forward and help fight poverty.

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

Re: how to get rows from another tmpl ?

Post by wene » Fri Dec 09, 2005 11:32 pm

my component manage musical instruments configs.
configs are built from a registered user.
others users can see configs but cant edit them if they dont own it.
so i use $my->id to check in my base table if the user owns the config.
here is a simplified example that builds a list table with checkboxes to edit or delete items.
php :

Code: Select all

$config_owner = $databaseLoadResult();
$canEdit = 0;
if ($my->id == $config_owner){
    $canEdit = 1;
}
$tmpl->addVar ("my-tmpl","canedit",$canEdit);
$my_tmpl = "my-tmpl-rows";
if ($canEdit != 1){
    $my_tmpl = "my-tmpl-rows-readonly";
}
$tmpl->addObject($my_tmpl,$rows,"row_");
html :

Code: Select all

<mos:tmpl name="my-tmpl" type="condition" conditionvar="canedit">
    <mos:sub condition="1">
    <table>
        <tr>
            <td>sel</td>
            <td>name</td>
            <td>details</td>
        </tr>
        <form name="bands" method="post" action="index.php">
            <input name="option"    value="com_mycomp"  type="hidden"/>
            <input name="task"      value=""            type="hidden"/>
            <input name="Itemid"    value="{ITEMID}"    type="hidden"/>
        <mos:tmpl name="my-tmpl-rows">
        <tr>
            <td><input type="checkbox" id="cb{ROW_NBR}" name="items_ids[]" value="{ROW_ID}"/></td>
            <td>{ROW_NAME}</td>
            <td>{ROW_DETAILS}</td>
        </tr>
        </mos:tmpl>
        </form>
    </table>
    </mos:sub>
    <mos:sub condition="__default">
    <table>
        <tr>
            <td>name</td>
            <td>details</td>
        </tr>
        <mos:tmpl name="my-tmpl-rows-readonly">
        <tr>
            <td>{ROW_NAME}</td>
            <td>{ROW_DETAILS}</td>
        </tr>
        </mos:tmpl>
    </table>
    </mos:sub>
</mos:tmpl>
i have much more options on the real code.
first, i have used only one tmpl with several conditions inside,
but the html became unreadable, so i prefeared to separate the readonly part.
( i prefear to rewrite the page rather than having canedit condition every 2 html line... :) )
Last edited by wene on Sat Dec 10, 2005 12:40 am, edited 1 time in total.

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

Re: how to get rows from another tmpl ?

Post by wene » Mon Dec 12, 2005 9:49 pm

i just realized that i hadnt say "thank you" for you answer.
My apologies.
Last edited by wene on Sun Dec 25, 2005 4:21 am, edited 1 time in total.


Locked

Return to “patTemplate”