alex-klock / razor-mediator-4-tridion

Automatically exported from code.google.com/p/razor-mediator-4-tridion
1 stars 4 forks source link

Razor helper file is not working from the WebDAV URL #2

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hi, 

I want to create some common function in Razor-Mediator templating which can be 
used in any other TBB,

As per the Razor doc, we can define these function in the helper file and need 
to map that file/TBB with the tridion with below setting 

    <razor.mediator cacheTime=”600” extractBinaries=”true” adminUser=”DOMAIN\Username”>
            <namespaces>
                <add namespace=”System.Linq” />
                <add namespace=”Tridion.ContentManagement” />
            </namespaces>
            <assemblies>
                <add assembly=”RazorSample.Test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=60ad7434f03dfcdc” />
                <add assembly=”C:\Program Files\Razor\Tests\Test.Sample.dll” />
            </assemblies>
            <imports>
                <add import=\"tcm:120-2233-2048\" />
                <add import=\"/webdav/020 Design/Building Blocks/System/TBBs/Helpers/razor-helpers.cshtml\" />
                <add import=\"C:\\Program Files\\Razor Mediator\\razor-helpers.txt\" />
                <add import=\"tcm:120-2200-2048\" publications=\"020 Design Master,030 Another Web Design\" />
            </imports>
            <importSettings includeConfigWhereUsed="true" includeImportWhereUsed="true" replaceRelativePaths="false" />
        </razor.mediator>

I am able to import successfully my all function when I defined the physical 
path in the config file.  

But, its not working when I defined the wevDAV URL in the config file, 

Could any one please help or let me know if i am missing any steps?

Thanks 

Priyank 

Original issue reported on code.google.com by joy.priy...@gmail.com on 22 Oct 2012 at 11:49

GoogleCodeExporter commented 9 years ago
Priyank - if you look at         
Tridion.Extensions.Mediators.Razor.RazorHandler.GetImportTemplateContent(), you 
will see that the webdav url is passed unchanged to the Tridion session. Have 
you verified that your webdav url can successfully retrieve the item from the 
Tridion API?

Original comment by dominic....@gmail.com on 25 Oct 2012 at 1:29

GoogleCodeExporter commented 9 years ago
It seems like your escaping the double quotes? Not sure if that's needed. We 
also reference our helper files in this way, which works fine (in 1.2 and 1.3):

<add 
import="/webdav/20%20Developer%20-%20Templates/Building%20Blocks/System/Libs/Raz
or/Helpers/RTBB_Helpers.cshtml" />

Note we also use %20 for spacing, I'm aware it should not be needed, but it's 
habit :).

Original comment by rwars...@gmail.com on 25 Oct 2012 at 1:36

GoogleCodeExporter commented 9 years ago
Marking as non-issue... haven't heard any updates are have heard reports of 
this issue from anyone else.

Original comment by alex@tahzoo.com on 21 Dec 2012 at 2:23

GoogleCodeExporter commented 9 years ago
Hi Alex, 

Sorry for not responded you earlier. 

Today, i am going to set-up razor helper function for new environment, and face 
same issue with internal TBB file, 

Just for update, I am using the following steps to use razor helper function in 
all others razor TBBs.

1. Created a TBB file Named as "Helper" which web dev Url is 
/webdav/03C%20Medical%20Content/Building%20Blocks/System/Templates%20Building%20
Blocks/Razor%20Templates/Helper.cshtml

In this file i wrote a simple "test" helper function like below

@helper test()
        {
        <p>Working correctly</p>
    }

2. Added this TBB path in the config file in razor section tag like below 
<add 
import="/webdav/02%20Global%20Design/Building%20Blocks/System/Templates%20Buildi
ng%20Blocks/Razor%20Templates/Helper.cshtml" />

3. Restarted the Com++ package and tridion services

4. Create a new razor TBB, and tried to call test() helper function like below

@test()

but when i save this file then getting the below error

Error:

TemplateCompileException: CS0103: The name 'test' does not exist in the current 
context 
 Line 48 Column 7: WriteLiteral("\r\n\r\n\r\n");
 * Write(test());
 }
 }
 }

 Stack Trace: 
 at Tridion.Extensions.Mediators.Razor.Templating.Compiler.Compile(IEnumerable`1 entries, IEnumerable`1 assemblyReferences)
 at Tridion.Extensions.Mediators.Razor.Templating.RazorTemplateGenerator.CompileTemplates(IEnumerable`1 assemblyReferences)
 at Tridion.Extensions.Mediators.Razor.RazorHandler.Compile(DateTime revisionDate)
Unable to save Template Building Block (tcm:0-0-0).

2.a Suppose, if i use a different approach in steps 2 and pass tcm uri instead 
of webdev path like below 

<add import="tcm:2-421-2048" />

Then i am getting the below different error

Error: The item tcm:0-421-2048 does not exist.

2.b But, i am successfully able to call that helper function if i create 
External Helper file and pass the physical path in the config file like below 

<add import="C:\Program Files (x86)\Tridion\Razor Mediator\helpers.cshtml" />
Note: This is a another file, which is used for different helper function and 
saved at the same above path

Then its working correctly.

I would like to go with approach explained in stpes 2 and 2.a for sake best 
practices. Could you please help me on same?

Thanks

Kind regards,
Priyank

Original comment by joy.priy...@gmail.com on 31 Jan 2013 at 12:20