28 October 2010 at 8:15pm
I've been thinking a bit about how to reuse a rendering.
Say, for instance, that I have a list of DataObjects that I want to render in a certain way, and I would like the rendering to be the exact same all over the site. On the frontpage, on the member page and so on. Perhaps I would like to use the same rendering on the same page but with to different lists (could be a list latest pages and just a list of pages). Both lists should look the exact same - and I dont like to repeat my code...
What I'm looking for is something like:
<% control MyCustomPageRenderer datasource="somedatasource" (should rather be an ID so that the controller could identify the control and bind the data to it) />
28 October 2010 at 9:26pm
Firstly to "re-use accross the site" I'd recommend placing the template into an include, then using...
<% include TemplateName %>
...where it is required.
the problem with what you are asking, I think, is that you want to pass a dynamic variable into this and this is not possible. what you can do is have the controller specify the data source in a different implementation of MyCustomPageRenderer in each different controller.
28 October 2010 at 9:43pm
Thanks for your feedback. The include would work if I only use the controller once on each page right?
But could you help me understand how to have the controller specify the data source in a different implementation?
28 October 2010 at 9:57pm
ok - I think I misunderstood then.
What if I would like to have the same rendering on the one page twice? then I could "bind" with data in the controller, but the name of the control <% control MyCustomRenderer %> would still be the same (since I can't change it, because I only want one)
It would nice to have something as <% control MyCustomRenderer as MyCustomRendererSecondList %>
and then in the code bind the other dataset that I want to display on the same page to the MyCustomRendererSecondList...
28 October 2010 at 10:22pm
the control AS othercontrol_id was just pseudo code to explain my wish... or how this could be done.
When passing a variable I would do it in the markup of the control and not when "calling" the control right?
When using <% control MyControl %> I am about to define/declare the markup for some data provided via MyControl function in then Controller right?
28 October 2010 at 10:38pm
Sorry but I simply do not follow what you are asking... Maybe something is lost in translation here... but as I said I advise reading the docs and doing the tutorials... this is where you will get to understand templating... or if you are committed to ss get the book. When you have done this and have something working or close to doing as you wish how about you post that?