Welcome, Guest. Please login or register.
Did you miss your activation email?
Sep. 02, 2010, 07:47:36 PM
53844 Posts in 11998 Topics by 11375 Members
Latest Member: elizablackmore7
News:
 
The PRADO Community » Prado v3.x » General Discussion » How to include one template on several parent templates? « previous next »
Pages: [1] Print
Author Topic: How to include one template on several parent templates?  (Read 1938 times)
piar
Senior Member
***

Karma: 5
Offline Offline

Posts: 144


View Profile
« on: Aug. 21, 2008, 04:28:28 PM »

I have two pages let us call them UserView (UserView.page, UserView.php) and AdminView (AdminView.page, AdminView.php). That two pages have some different components and behaviours but also some common components and behaviour. So to avoid code duplication I want to put that common parts to separate files - let say: Common.tpl (derived from TTemplateControl) and Common.php. But I do not know how to include that Common file on UserView and AdminView.
There is template injection mechanism implemented by: TContent with TContentPlaceHolder but it works from other side: when there is one master and several child templates. In my situation that could works if I would make master from Common but it is not exactly what I want (and in that situation it would not be correct from logical point of view). For example if Common would be master I will get:
Common.page
Code:
<!-- some common components -->
<com:TContentPlaceHolder ID="CommonPH" />
So now in both UserView and AdminView common components will be above specific commponents but I would like to have them in another place in UserView and AdminView.

I would like to have something like that:
UserView.page
Code:
<!-- some UserView specific components -->
<!-- include Common components here -->
<!-- other UserView specific components -->

AdminView.page
Code:
<!-- some AdminView specific components -->
<!-- include Common components here -->
<!-- other AdminView specific components -->

Is there a way to make inclusion like that?
Logged
nilsz
Senior Member
***

Karma: 0
Offline Offline

Posts: 51



View Profile
« Reply #1 on: Aug. 21, 2008, 04:40:07 PM »

What about:

main.tpl
Code:
<com:TContentPlaceHolder ID="Admin1" />
<com:TContentPlaceHolder ID="Common" />
<com:TContentPlaceHolder ID="Admin2" />


Logged
piar
Senior Member
***

Karma: 5
Offline Offline

Posts: 144


View Profile
« Reply #2 on: Aug. 21, 2008, 04:51:19 PM »

What about:

main.tpl
Code:
<com:TContentPlaceHolder ID="Admin1" />
<com:TContentPlaceHolder ID="Common" />
<com:TContentPlaceHolder ID="Admin2" />


Thanks for that suggestion but it is not exactly what I want. Let us say that in UserView common part should be in divs <div></div> and in AdminView in some table <td></td> like that:

UserView.page
Code:
<div style="width: 300px">
<!-- include here somehow Common.tpl -->
</div>

AdminView.page
Code:
<table>
<tr>
<td>Description</td>
<td><!-- include here somehow Common.tpl --></td>
</tr>
</table>

This probably can not be made when we will make Common as master and UserView with AdminView as childs. That is why I am looking for some other solution where Common would not be master but would be somehow included in UserView and AdminView.
Logged
piar
Senior Member
***

Karma: 5
Offline Offline

Posts: 144


View Profile
« Reply #3 on: Aug. 21, 2008, 05:01:46 PM »

In fact I want something like for example ItemRenderer for TTemplateColumn in TDataGrid where we are making:
Code:
<com:TTemplateColumn
        ID="Column"
        ItemRenderer="Application.pages.SomeRenderer"
        />

SomeRenderer is tpl file and is included in main page in that column for every row of DataGrid. I want to have exactly same thing but without TDataGrid - I just want to include tpl file in two page files.
Logged
nilsz
Senior Member
***

Karma: 0
Offline Offline

Posts: 51



View Profile
« Reply #4 on: Aug. 21, 2008, 05:07:07 PM »

Maybe this is an idea:

main.tpl
Code:
<com:TContentPlaceHolder ID="Admin1" />

<com:TControl Visible="<%= !$this->User->IsAdmin %>" >
<div>
<com:TContentPlaceHolder ID="Common" />
</div
</com:TControl>

<com:TControl Visible="<%= $this->User->IsAdmin %>" >
<table><tr><td>
<com:TContentPlaceHolder ID="Common" />
</td></tr></table>
</com:TControl>

<com:TContentPlaceHolder ID="Admin2" />
Logged
nilsz
Senior Member
***

Karma: 0
Offline Offline

Posts: 51



View Profile
« Reply #5 on: Aug. 21, 2008, 05:12:53 PM »

In fact I want something like for example ItemRenderer for TTemplateColumn in TDataGrid where we are making:
Code:
<com:TTemplateColumn
        ID="Column"
        ItemRenderer="Application.pages.SomeRenderer"
        />

SomeRenderer is tpl file and is included in main page in that column for every row of DataGrid. I want to have exactly same thing but without TDataGrid - I just want to include tpl file in two page files.

Just make a component of the tpl. you can include it then in any page you want with

<com:MyComponent ID="common">
Logged
piar
Senior Member
***

Karma: 5
Offline Offline

Posts: 144


View Profile
« Reply #6 on: Aug. 21, 2008, 05:52:04 PM »

Just make a component of the tpl. you can include it then in any page you want with

<com:MyComponent ID="common">

Yes! That is what I was looking for! I made my own control from that common part and now it works exactly as I wanted to. Thank you for help! Smiley
Logged
m_ologin
Newbie
*

Karma: 0
Offline Offline

Posts: 1


View Profile
« Reply #7 on: Jul. 29, 2010, 03:35:10 PM »

Hi,

Could you please explain how you went from a template to a component?
Logged
Pages: [1] Print 
« previous next »
Jump to: