Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Thor Madsen-Holm 82 posts 212 karma points c-trib
    Jun 19, 2011 @ 18:17
    Thor Madsen-Holm
    1

    RenderPage question

    Hi, I just started playing around with Razor and I ran into a little problem.

    I have a razor macro called MetaTags with an assosiated razor file (MetaTags.cshtml), the file looks like this:

    @{    
        @RenderPage("GlobalVariables.cshtml")
        <h2>@settingsNode.Name</h2>
    }

    As you can see, the first thing I do is render another razor file (GlobalVariables.cshtml) which looks like this:

    @using umbraco.MacroEngines
    @inherits umbraco.MacroEngines.DynamicNodeContext
    
    @{
        dynamic settingsNode = new DynamicNode(1049);    
    }

    So what I am trying to do is getting the name of the settingsNode i declared in the Globalvariables.cshtml file. However I get an error when loading the page, that says the following: 

     

    Error loading Razor Script MetaTags.cshtml
    \macroScripts\MetaTags.cshtml(3): error CS0103: The name 'settingsNode' does not exist in the current context

     

    Is ii possible to make the settingsNode exist in the context of the MetaTags file?
    I am newbie when it comes to Razor, so any help will be much appreciated :-)

    /Thor

  • dimi309 245 posts 579 karma points
    Jun 19, 2011 @ 20:49
    dimi309
    1

    Hi Thor,

    Unfortunately, as far as I have been able to find out, RenderPage just produces the output of a .cshtml script. It does not offer access to variables declared in it.

    The cool thing is that you can do something like

    string name = RenderPage("GetName.cshtml")

    to place whatever output derives from GetName.cshtml in the "name" variable.

    There are some ways to reuse data produced or retrieved in a script from another script, which have been discussed here:

    http://our.umbraco.org/forum/developers/razor/20700-Including-and-sharing-variable-throug-Razor-files

    I hope that this helps!

    Dimitri

  • Thor Madsen-Holm 82 posts 212 karma points c-trib
    Jun 20, 2011 @ 11:20
    Thor Madsen-Holm
    0

    Hi Dimitri, 

    Thanks alot, that pointed me in the right direction :-)

    /Thor

Please Sign in or register to post replies

Write your reply to:

Draft