14

In a Component Template TBB, you don't have (direct) access to the Page object. The property ContextItem would return the Component that is being rendered with the current Component Tempalte. Please check that, as I'm not familiar with what TridionHelper should do. Hence your code ContextItem as Page will return null. Back to your question -- how to pass ...


12

Some tags are written out automatically, for example if you use the RenderComponentPresentation() method it will output the markup for a component presentation, and if you use RenderComponentField() it will output the markup for a field. New in 2013 SP1 are the FieldStartMarker(), FieldValueStartMarker(), FieldEndMarker() and FieldValueEndMarker() ...


11

Since the @ signifies that you are breaking out of text mode you need to use a text tag to add the line breaks in for plain text. @if(Fields.Title != null) { <text>@Fields.Title</text> } @if(Fields.Subtitle != null) { <text>@Fields.Subtitle</text> } Outputs: Title Subtitle


9

I had the same issue, I ended by having my custom razor functions in a cshtml file in my .Net Project. <razor.mediator cacheTime="60" extractBinaries="true" adminUser="Administrator"> .. <imports> <add import="[MyProjectPath]\Functions.cshtml" /> <imports> .. </razor.mediator> I hope this helps.


9

According to this helpful post by Dominic Cronin You can use "text" tags in order to do this. So the final if statement looks like this: @if (Fields.releaseMediaTitle == null) { <text> <div class="col-sm-12"> <a href="http://www.example.org"> </text> } else { <text> <div class="col-sm-8"> &...


8

This is due to the (optional) management of dependencies that is a feature of the Razor Mediator. If (in Tridion.ContentManager.config) you set the includeConfigWhereUsed attribute to true in the Razor configuration section then every Razor TBB you subsequently create or edit will have a dependency on Razor TBB(s) set to globally import in the imports ...


8

Your solution seems fine, except for the hardcoding of the CT's TCM ID. So it sounds like you need a way to reference the component template without hardcoding the TCM ID. Have a look at the comments in the answer here: https://stackoverflow.com/a/10802912/1284894 The solutions discussed are to: add a Parameter schema on the DWT TBB that specifies the ...


8

Alex Klock's website CodedWeapon where we had gotten the original instructions on how to load an external dll for use in Razor shows 2 ways to reference the assembly. The solution to our problem lies in the second method, namely referencing the dll from the GAC: <razor.mediator extractBinaries="true" adminUser="NT AUTHORITY\SYSTEM"> <namespaces&...


8

You have three options to retrieve any values from the package, which would include parameter schemas: @Package.ItemName @Package.GetByName("ItemName").GetAsString() @Package.GetValue("ItemName")


8

Have you referenced the assembly (in the GAC) within your Tridion.ContentManager.config file? For example: <razor.mediator cacheTime="60" extractBinaries="true" adminUser="DOMAIN\AdminUser"> <namespaces> <!-- ... --> </namespaces> <assemblies> <add assembly="RazorSample.Test, Version=1.0.0.0, Culture=...


8

There are two parts to this answer. The first was pointed out by Jonathan Williams, I was missing the assembly reference in the razor.mediator configuration <razor.mediator cacheTime="60" extractBinaries="true" adminUser="DOMAIN\AdminUser"> <namespaces> <!-- ... --> </namespaces> <assemblies> <add ...


8

It turns out that I was on the correct path, but had missed adding the proper using statement to my TBB. By inserting @using System.Globalization; at the top of my TBB I was able to use either of the methods that I tried originally without issue.


7

Here are the RAZOR functions that we wrote to accomplish this: (hope this helps someone) @functions{ @* ========================================================================================== <summary>Get the TCM number based on the WebDAV path sent in.</summary> <param name="webdav">WebDAV path of the object to find TCM of&...


6

Try using the <text> wrapper around your statements, in order to help the parser identify them properly. See https://stackoverflow.com/questions/5369540/razor-renderpartial-exception-expected


6

Have you tried: @Package.GetValue("Component.Metadata.ref")


6

You could use: <text>stars:</text>@Metadata.stars Read more here: http://weblogs.asp.net/scottgu/archive/2010/12/15/asp-net-mvc-3-razor-s-and-lt-text-gt-syntax.aspx


6

The Razor Mediator has excellent documentation, including the info you're looking for: https://code.google.com/p/razor-mediator-4-tridion/downloads/detail?name=RazorMediatorDocumentation_v1.3.3.docx In your case I think you'll want to use the @Publication.PublicationUrl to get the URL then concatenate the @Page.FileName onto the end of it.


5

Because the @ character is special in Razor, to output a literal @ you need to double it. So instead of <%@page pageEncoding="UTF-8" %> you must say: <%@@page pageEncoding="UTF-8" %>


5

I think it may have something to do with the option to allow Where Used relationships for Razor TBBs, I haven't traced the code through, but I think when a template is compiled it updates the Where used relationships, even if there are no imports, but for this it needs a session. Try setting includeImportWhereUsed to false, and while you are at it probably ...


5

I have not had to upgrade the Razor mediator yet. However, with the recent memory leak fixes, in v1.3.3 I will probably be doing this soon. The upgrade should just be a matter of uninstalling v1.2 and then re-installing v1.3. The steps that I would probably take are: Take the CMS (CME and Core Service) offline to prevent users from trying to publish (or ...


5

To expand a little on what your problem is and why your solution won't work; the IsFirst property that you're using is part of the Razor Mediator's DynamicItemFields class and is explicitly set by the library, not a built-in part of any .NET collection type. By contrast, when you use the Enumerable.First method as in your MVC example, you are not checking ...


5

Razor seems to be registered with different id or its not installed at your CMS server, but template expecting it with Id:8 Check your Tridion.ContentManager.config, it should be like below: <add id="8" name="RazorTemplate" mimeType="text/x-tcm-cshtml" hasBinaryContent="false" contentHandler="Tridion.Extensions.Mediators.Razor.RazorContentHandler, ...


5

Many ways to do this, but two that haven't been listed: @{ var colorClass= Fields.subtitle != null ? "subtitleColor" : "no-color"; } <div class="@colorClass"> That has the advantage of using a variable you set in the template itself, and you can of course group them near the top if there is more than one. Also, which is the syntax I think you ...


5

I think you're right Harald, for 2013 it appears as though you don't need to call the "Initalize" method but can instead pass TridionHelper.Engine and TridionHelper.Package to the "OutboundEmailFunctionSource" constructor. Try this method: @{ var OutboundEmail = new Tridion.OutboundEmail.Templating.OutboundEmailFunctionSource(TridionHelper.Engine, ...


5

AFAIK, you won't be able to get the Keyword titles directly in a Razor TBB; however, you can create your own custom function in the Razor TBB that manipulates the XML and returns the titles. The example below is a custom function that takes in as parameter a category XML string and returns the Keyword titles as a list: @using System; @using System....


5

The Razor Mediator is and community built extension and thus is not supported by SDL. However it is using the Modular Templating Framework and its supported extension points, so from that perspective, I would expect the Razor Mediator to remain to work. If not you probably want to contact its owner and let him know. As for the extension points being ...


4

The process of upgrading the Razor Mediator is to uninstall it and then install again. I would suggest to make a copy of the Razor configuration settings at the bottom of your Tridion.ContentManager.config file before uninstalling the 1.2 version. The good news is the 1.3 version patches a memory leak that would require restarting the Publisher service on ...


4

I'm not sure why the contextitem would be null (i'll do some tests myself), but you could solve this the other way around. Instead of getting page metadata from a component template, you could put the required page metadata in the context variables You would put this code in a TBB on your page template (before you call your rendercomponentpresentations() ...


4

I think you might be better to write that like this using a terniary operator <a href="#@fields.tab_target_name" @(fields.IsFirst ? "class=\"active\"" : "")> As Mihai points out the parser is struggling to identify what is code and what isn't. This should make it a little easier for it.


4

Just in case anyone is still having this problem, I solved it by adding the NT AUTHORITY\SYSTEM account (the account that the Publisher Service runs under by default) as an impersonation user. This is done in the %TRIDION_HOME%/config/Tridion.ContentManager.config file, and mine now looks as follows: <impersonationUsers> <clear /> <...


Only top voted, non community-wiki answers of a minimum length are eligible