Copied to clipboard

Flag this post as spam?

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


  • Garrett Fisher 341 posts 496 karma points
    Feb 26, 2016 @ 14:45
    Garrett Fisher
    0

    Optimus: How to Add to Template?

    Hi,

    I feel dumb asking this but I've installed Optimus (1.4 with U7.4) and everything seems to be working fine/great, and I'm excited! I created a couple of bundles but I can't figure out how to add them into the template.

    In the template edit UI, if I click on "Create script/style bundle", the right side bar comes up and says, "Please select at least 1 script or stylesheet on your template before creating a bundle." But the rest of that area is empty -- there is no list, even though my bundles exist under Bundling > Styles.

    I am happy to add it manually but I also can't find where the files are stored.

    Ideas?

    Thanks,

    Garrett

  • Comment author was deleted

    Feb 26, 2016 @ 14:50

    Hi Garret,

    You'll need to add the following snippet:

    @Scripts.Render("~/bundles/yourBundle)

    or

    @Styles.Render("~/bundles/yourBundle") (if it's a styles bundle)

  • Comment author was deleted

    Feb 26, 2016 @ 14:50

    The UI tool is used in the following way as shown in the video http://www.nibble.be/?p=238

  • Garrett Fisher 341 posts 496 karma points
    Feb 26, 2016 @ 15:21
    Garrett Fisher
    0

    Thanks so much for your attention, Tim!

    The video is EXCELLENT! Very helpful to understand the workflow.

    However....

    With only:

    <umbraco:Macro runat="server" language="cshtml">
        @Styles.Render("~/bundles/TestBundle")
    </umbraco:Macro>
    

    I get the following error:

    The name 'Styles' does not exist in the current context.
    

    So then I try these using/inherits lines with it:

    <umbraco:Macro runat="server" language="cshtml">
         @using System.Web.Optimization
         @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
         @Styles.Render("~/bundles/TestBundle")
    </umbraco:Macro>
    

    And get this error:

    Context Must Implement System.Web.WebPages.WebPage.
    

    So I am a bit lost. I am sure my syntax is just wrong -- I am at best a a Razor "aficionado" ;). My umbracoSettings.config is set to <defaultRenderingEngine>Webforms</defaultRenderingEngine> for other reasons, which is why I need it to be in a cshtml macro. Will this work?

    Thank you again,

    Garrett


  • Comment author was deleted

    Feb 26, 2016 @ 15:22

    Ah ok you are still running webforms, there should be an equivalent to @Styles.Render, let me check

  • Comment author was deleted

    Feb 26, 2016 @ 15:23
  • Comment author was deleted

    Feb 26, 2016 @ 15:24

    So in web.config add

    <namespaces>
        <add namespace="System.Web.Optimization" />
    </namespaces>
    

    and then

    <%: Scripts.Render("~/bundle/GlobalHead") %>
     <%: Styles.Render("~/Content/Global") %>
    
  • Garrett Fisher 341 posts 496 karma points
    Feb 26, 2016 @ 15:25
    Garrett Fisher
    0

    Ok, thanks! Thing is, I am actually running other Razor code in this same template, a la:

    <umbraco:Macro runat="server" language="cshtml">
        @{
            blah blah;
        }
    </umbraco:Macro>
    

    So I would thing it would work.... Let me know what you find! And thanks sincerely for your very timely assistance.

    //Garrett

  • Comment author was deleted

    Feb 26, 2016 @ 15:27

    ok, don't think you need the @inherits Umbraco.Web.Mvc.UmbracoTemplatePage in your inline razor so should just be

    @using System.Web.Optimization

    @Styles.Render("~/bundles/TestBundle")

  • Garrett Fisher 341 posts 496 karma points
    Feb 26, 2016 @ 15:30
    Garrett Fisher
    0

    Thanks, I already had the web.config entry from the install script. This syntax change made the error(s) go away, and it writes to the page:

    <link href="/bundles/TestBundle" rel="stylesheet"/>
    

    But there is no /bundles folder so of course this results in a 404. What do I need to do to get the virtual paths working?

    //Garrett

  • Comment author was deleted

    Feb 26, 2016 @ 15:32

    How did you call your bundle? Is there an entry in the reservedpaths app setting (that makes sure umbraco ignores the bundles path)?

  • Garrett Fisher 341 posts 496 karma points
    Feb 26, 2016 @ 15:37
    Garrett Fisher
    0

    Yes, there is an entry in reservedpaths. Not sure why the querystring is not appended using the classic ASP.NET tags.

    //Garrett

  • Comment author was deleted

    Feb 26, 2016 @ 15:33

    Must say it's been a while since I looked at the package so not that fresh in my mind anymore, but will spin up the test site

  • Comment author was deleted

    Feb 26, 2016 @ 15:34

    So the app setting should loook like , then the umbraco 404 won't kick in

  • Comment author was deleted

    Feb 26, 2016 @ 15:35

    oops html got eaten

    should look like

    <add key="umbracoReservedPaths" value="~/umbraco,~/install/,~/bundles/" />
    
  • Garrett Fisher 341 posts 496 karma points
    Feb 26, 2016 @ 15:35
    Garrett Fisher
    1

    THIS IS OVER :)

    <umbraco:Macro runat="server" language="cshtml">
         @using System.Web.Optimization
         @Styles.Render("~/bundles/TestBundle")
    </umbraco:Macro>
    

    Is the magic code!

    This results in the following output:

    <link href="/bundles/TestBundle?v=xhyTBmZxtiJC8tsimWFI3XXU-_OJIRdm9em_jMT8gBc1" rel="stylesheet"/>
    

    I earnestly appreciate your help, Tim. CHEERS!

    //Garrett

  • Comment author was deleted

    Feb 26, 2016 @ 15:36

    Woohoo, glad you have it working!

  • Garrett Fisher 341 posts 496 karma points
    Feb 26, 2016 @ 15:39
    Garrett Fisher
    0

    Me too -- and as I said, very exciting package. I had been doing this outside of Umbraco with four separate U instances so this is pretty damned slick. GREAT WORK!

    Now to try out SASS so "Let's go to the videotape!"

    A million thanks, Garrett

  • Comment author was deleted

    Feb 26, 2016 @ 15:40

    Glad you like it :)

  • Garrett Fisher 341 posts 496 karma points
    Feb 26, 2016 @ 20:55
    Garrett Fisher
    0

    It's amazing.

    Stumbling a bit with the SASS provider, though. My bundle isn't including three .scss files which are in my main.scss imports, though, throwing errors about a variable not being defined -- but it is defined.

    main.css:

    ........
    
    @import "mediaqueries";
    @import "mixins";
    @import "home";
    @import "dog";
    @import "cat";
    

    The moment the compiler gets to this line in _home.scss, I get this error:

    During translation of SCSS-code, readed from the file '/css/_home.scss', to CSS-code syntax error has occurred. See more details: Message: Undefined variable: "$medium-up". File: /css/_home.scss Line number: 201
    

    That line is:

    @media #{$medium-up} {
    

    But that var is defined in _mediaqueries.scss, which is prior to _home.scss:

    $medium-up: "#{$screen} and (min-width:#{lower-bound($medium-range)})" !default;
    

    And _mixins.scss, which is imported prior to _home.scss, uses variables defined here as well and compiles okay (I think; there are no errors saving that one).

    I get the same error on _cat and _dog. Seems like I'm doing everything right here. CSS file main.css is generated and minified and served in my bundle, but I can't seem to get past these errors to complete this.

    Ideas? I'd really appreciate any further counsel on the SASS provider.

    Thanks again,

    Garrett

Please Sign in or register to post replies

Write your reply to:

Draft