Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Executing an item in the package as a Dreamweaver Template

Does anybody know if it is possible in a compound template to use a string item in the package and execute it as if were a dreamweaver template? And whether you apply the same method to other mediators (like razor)?

Thanks Mark

like image 836
Mark Cooper Avatar asked Jun 13 '12 14:06

Mark Cooper


2 Answers

I suspect this is not possible.

Package.EvaluateExpression may be useful, but as the name suggests it'll only work on expressions, not large snippets of code with embedded expressions (i.e. TEL)

Engine.GetMediator expects a Template and returns the appropriate Mediator for it. Your problem then is that the IMediator interface only defines the Transform method, which requires an Engine, a Template and a Package.

I can't think of any elegant ways around these. Maybe write your own Mediator, but that would still expect a Package, not a string, so you'd have to first store the string based Item from another TBB.

My advice: Sounds like you need to go back to the drawing board and find an alternative solution to your problem.

like image 101
David Forster Avatar answered Nov 19 '22 08:11

David Forster


I'm afraid that won't be possible on just any item in the Package, since the Engine expects Templates to be based on Tridion items.

If your Template Item is based on a Tridion Item you can probably get pretty far by starting at the Engine.GetMediator method. If it isn't, you'll have to find some way to turn it into a valid Template object.

Template template = ...
IMediator mediator = engine.GetMediator(template);
mediator.Transform(engine, template, package);

When I have to create a Component object from a Tridion-based Item in the Package, I normally do something like this:

Component component = new Component(item.GetAsXmlDocument().DocumentElement, 
                                    engine.GetSession);

I haven't tried, but expect that you can do the same for a Template - given that you start with a valid Item from the Package representing a Template to begin with. You can probably clone the XML from an existing Item or find some other way to fake it.

If you get this to work, it will work across all registered template types. The Engine provides no special treatment for the types that come with Tridion.

like image 40
Frank van Puffelen Avatar answered Nov 19 '22 08:11

Frank van Puffelen