Copied to clipboard

Flag this post as spam?

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


  • Nate 143 posts 184 karma points
    May 03, 2013 @ 00:09
    Nate
    0

    Access <head> section from razor script?

    I need to put some facebook meta data in the head section of a page.  The data lives inside of a razor script.

    I have a contentplaceholder called "cphScripts" that lives in the master page that the macroscript (razor) lives in.

    Is there a way to access it from the razor script?  Is there another way to get my data into the head section?

  • Fuji Kusaka 2203 posts 4220 karma points
    May 03, 2013 @ 08:57
    Fuji Kusaka
    100

    Hi Nate,

    You can simply to this by adding an Inline Razor Macro in your template within the ContentPlaceHolder.

    <asp:Content ContetenPlaceHolderId="cphScripts" runat="server">
            <umbraco:Macro runat="server" language="cshtml">

    @{

    }
          </umbraco:Macro>
    </asp:Content>
  • Nate 143 posts 184 karma points
    May 23, 2013 @ 20:39
    Nate
    0

    I just marked you as an answer but I think we have it backwards.

    I have a CSHTML file and I want to add the asp:Content section.

    I think you're showing the above that I have a regular template page and you add the razor to that.

  • Fuji Kusaka 2203 posts 4220 karma points
    May 23, 2013 @ 20:49
    Fuji Kusaka
    0

    Hi Nate,

    Yes am in a regulare template here. What were you trying to achive ?

  • Nate 143 posts 184 karma points
    May 23, 2013 @ 21:00
    Nate
    0

    My structure is like this.

    Template 1 -> Template 2 -> Template 3 -> Macro (razor .cshtml file)

    In side the razor file, I want to access that cphScripts content.

    So my file is like the one below, but the <asp:content is not recongnized.

    Thanks man!

    @inherits umbraco.MacroEngines.DynamicNodeContext 
    
        @{
    //Some code here
    }
    <asp:content ContentPlaceHolderId="cphScripts" runat="server">
      <meta property="fb:app_id"      content="123456" />
      <meta property="og:type"        content="fitness.bikes" />
      <meta property="og:url"         content="@url" />
      <meta property="og:title"       content="@careerWorkout.WorkoutName" />
      <meta property="og:description" content="@workoutNotesText />
      <meta property="og:image"       content="@careerWorkout.PictureLocation" />
    </asp:content>
    <p>There's some stuff in here</p>
  • Fuji Kusaka 2203 posts 4220 karma points
    May 23, 2013 @ 21:16
    Fuji Kusaka
    0

    So you want to do something like this if am not mistaken here

    <asp:Content ContetenPlaceHolderId="cphScripts"runat="server">
           
    <umbraco:Macrorunat="server"language="cshtml">

    @{
    if(@Model.HasValue("careerWorkout")){
    <metaproperty="og:title"content="@Model.careerWorkout"/>
    }
    }
         
    </umbraco:Macro>
    </asp:Content>
Please Sign in or register to post replies

Write your reply to:

Draft