Tridion C # SDL snippet cannot find fields for engine, package or log in context

I am new to Tridion development and I have the first β€œmain” problem. I wrote a simple C # code snippet in TBB (using a text editor of content) and I tried to use the fields for the engine, package and log (since, as I know, they are accessible by Tridion), but I get the error "name does not exist in the context". Here is the code:

<%@ Page Language="C#" ContentType="text/html" ResponseEncoding="utf-8" %> <div> <!-- TemplateBeginRepeat name="Component.Fields.crociera" --> <!-- TemplateBeginIf cond="prezzo<250" --> Go to @@ location@ @<br/> <!-- TemplateEndIf --> <!-- TemplateEndRepeat --> </div> <% String ts = DateTime.Now.ToString("d MMM yyyy"); Response.Write("<br/>"+ts); engine.getSession(); %> 

When I save TBB and publish the page, I get this error:

 Compilation Error Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. Compiler Error Message: CS0103: The name 'engine' does not exist in the current context Source Error: Line 31: Response.Write("<br/>"+ts); Line 32: engine.getSession(); Line 33: %> Line 34: </div> Source File: c:\inetpub\wwwroot\stage\pj\ricerca\ricerca.aspx Line: 32 

Perhaps I missed something or something was wrong, did someone recognize the problem?

+4
source share
2 answers

The Engine object that you use is part of the Tridion TOM.NET API, available only to your code when the element is published.

Once the ASPX page reaches the front-end server, the TOM.NET API is no longer available. This is partly due to the fact that Tridion Content Manager is simply not available from your web server.

Instead of programming Tridion Content Manager through your TOM.NET API, you need to program to deliver Tridion content through your API. You can find documentation for common cases in Live Docs (login required).

+11
source

You can find information on how to correctly create a C # fragment in How to add user-defined methods in C # TBB (C # code fragment)?

+3
source

Source: https://habr.com/ru/post/1444559/


All Articles