Copied to clipboard

Flag this post as spam?

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


  • Kate 267 posts 610 karma points
    Oct 07, 2013 @ 21:42
    Kate
    0

    Recursiv images

    Hi

    Is there anyone who can help get the pictures recursiv?

    Here is what I got so fare:

    <div class="col img-item">
    @if(Model.HasValue("photo1")){
    var selectedMedia1 = @Model.Media("photo1");
    <img src="@selectedMedia1.umbracoFile" alt="@selectedMedia1.Name" class="projectImg1 rotate5deg" />
    }
    </div>
  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Oct 07, 2013 @ 21:49
    Dennis Aaen
    0

    Hi Kate,

    I do it this way and the logo is set on the homepage node i my case.

    @{
       
    var imageId =Model.AncestorOrSelf().PageLogo;
       
    var media =Library.MediaById(imageId);
         
    <img src="@media.umbracoFile" alt=""/>
    }

    Have you tried something like this?

    <div class="col img-item">
             
    var selectedMedia1 =
    Model.AncestorOrSelf().photo1;
             
    <img src="@selectedMedia1.umbracoFile" alt="@selectedMedia1.Name" class="projectImg1 rotate5deg"/>
               

    <div>

    /Dennis

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Oct 07, 2013 @ 22:16
    Dennis Aaen
    0

    Hi again Kate,

    I also just testet with this version. And it also seems to work with images.

    <divclass="col img-item">
             
    var selectedMedia1 =
    Model._photo1;
             
    <img src="@selectedMedia1.umbracoFile" alt="@selectedMedia1.Name" class="projectImg1 rotate5deg"/>
    </div>

    As Jeavon describes in his post in this topic.

    http://our.umbraco.org/forum/developers/razor/45258-how-do-I-get-a-textstring-recursiv-in-razor

    /Dennis

  • Kate 267 posts 610 karma points
    Oct 07, 2013 @ 22:27
    Kate
    0

    Hi Dennis

    I can't get it to work :-(

    I have tried this:

    @{
    var imageId = Model.AncestorOrSelf().photo1;
    var media = Library.MediaById(imageId);
    <img src="@media.umbracoFile" alt=""/>
    <p>Her imageId: @imageId </p>
    <p>Her media: @media </p>
    }

    I dont get any output from @imageId and @media

    I have also tried your other exampel, but no luck. Here I dont get past this line:

    @if(Model.HasValue("photo1"))

    I can understand this, beacause one the current page there is no content in photo1.

  • Kate 267 posts 610 karma points
    Oct 07, 2013 @ 22:38
    Kate
    0

    I just saw your comment about: var selectedMedia1 = Model._photo1; and i think you are on the right track :-)
    But I get an error:

    e:\data\eventureexplore.dk\web\macroScripts\635167820583810946_testerMacro.cshtml(46): error CS0103: The name 'selectedMedia1' does not exist in the current context

    <div class="col img-item">
    var selectedMedia1 = @Model._photo1;
    <img src="@selectedMedia1.umbracoFile" alt="@selectedMedia1.Name" class="projectImg1 rotate5deg"/>
    </div>

     

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Oct 07, 2013 @ 22:40
    Dennis Aaen
    0

    Okay Kate,

    I don´t think uppercase should do the difference.

    I think I spotted the thing that give you the error. Try to remove the @ sign before Model in the variable. And see if it goes better.

    <div class="col img-item">
         var selectedMedia1 = Model._photo1;
         
    <img src="@selectedMedia1.umbracoFile" alt="@selectedMedia1.Name" class="projectImg1 rotate5deg"/>
    </div>

    /Dennis

  • Kate 267 posts 610 karma points
    Oct 07, 2013 @ 22:50
    Kate
    1

    Thanks for your patience

    Your last exampel gave me a new error on the page:
    Error loading MacroEngine script (file: testerMacro.cshtml)

    I just don't understand why I cant write an variable.

    Her is my code. maybe you can see what I'm doing wrong.

    @* The fun starts here *@

    @if(Model.HasValue("_headerProject")){

    <div class="destinationProject">
    <div class="cntDestinationProject">
    <h2>
    @Model._headerProject
    </h2>
    <div class="col col1 text-item">
    <h3>@Model._leftColHeader </h3>
    @Model._leftColText
    </div>

    <div class="col col2 text-item">
    <h3>@Model._rightColHeader</h3>
    @Model._rightColText
    </div>
    <div class="col img-item">
    var selectedMedia1 = @Model._photo1;
    <img src="@selectedMedia1.umbracoFile" alt="@selectedMedia1.Name" class="projectImg1 rotate5deg"/>
    </div>



    </div>
    </div>
    }

     

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Oct 07, 2013 @ 22:53
    Dennis Aaen
    0

    Hi Kate,

    Try this one:

    @*The fun starts here *@
       
     
    @if(Model.HasValue("_headerProject")){
                   
         
    <div class="destinationProject">
               
    <div class="cntDestinationProject">
               
    <h2>
                   
    @Model._headerProject
               
    </h2>
                <div class="col col1 text-item">
                 <h3>@Model._leftColHeader </
    h3>
                   
    @Model._leftColText
               
    </div>
                   
                <div class="col col2 text-item">
                    <h3>@Model._rightColHeader</
    h3>
                   
    @Model._rightColText
               
    </div>
                 <div class="col img-item">
                      var selectedMedia1 = Model._photo1;
                      <img src="@selectedMedia1.umbracoFile" alt="@selectedMedia1.Name" class="projectImg1 rotate5deg"/
    >
                 
    </div>
             
             
                 
                </
    div>
           
    </div>
     
    }

    Just heightligted the difference with bold. I remove the @ sign in the variable.

    /Dennis

  • Kate 267 posts 610 karma points
    Oct 07, 2013 @ 23:02
    Kate
    1

    When I write it like this, it works. But I have to have this ekstra if-sentens

    @* The fun starts here *@

    @if(Model.HasValue("_headerProject")){

    <div class="destinationProject">
    <div class="cntDestinationProject">
    <h2>
    @Model._headerProject
    </h2>
    <div class="col col1 text-item">
    <h3>@Model._leftColHeader </h3>
    @Model._leftColText
    </div>

    <div class="col col2 text-item">
    <h3>@Model._rightColHeader</h3>
    @Model._rightColText
    </div>
    <div class="col img-item">
    @if(Model.HasValue("_headerProject")){
    var selectedMedia1 = @Library.MediaById(Model._photo1);
    <img src="@selectedMedia1.umbracoFile" alt="xx" class="projectImg1 rotate5deg"/>
    }
    </div>



    </div>
    </div>
    }

    any good explanation??

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Oct 07, 2013 @ 23:07
    Dennis Aaen
    0

    Nope I don´t have an good explanation for that.

    But have you tried to see if you could write it shorter by this:

    <div class="col img-item">
         var selectedMedia1 = Model._photo1;
    var media = Library.MediaById(selectedMedia1);
         
    <img src="@media.umbracoFile" alt="@media.Name" class="projectImg1 rotate5deg"/>
    </div

    Without the if statement. I don´t know if it actually will work.

    /Dennis

  • Kate 267 posts 610 karma points
    Oct 07, 2013 @ 23:15
    Kate
    0

    I have tried that.

    I think I have writen something wrong in the beginning af the code. i just cant see what it is.

    But thanks for your help. Once again you have gotten me on the right track :-)

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Oct 07, 2013 @ 23:20
    Dennis Aaen
    0

    You are very welcome Kate,

    This I think would work for you. So you could drop the if-statement.

    <div class="col img-item">
         var selectedMedia1 = Model._photo1;
     
    var media = Library.MediaById(selectedMedia1);
         
    <img src="@media.umbracoFile" alt="@media.Name" class="projectImg1 rotate5deg"/>
    </div>

    You have to use the library method Library.MediaById when you have with images to do. Then you got the ID of the image, from there you have to use the @umbracoFile, to make it to a path to the image.

    /Dennis

  • Kate 267 posts 610 karma points
    Oct 07, 2013 @ 23:40
    Kate
    0

    Sorry, it still gives me an error:   "The name 'media' does not exist in the current context"

     

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Oct 07, 2013 @ 23:44
    Dennis Aaen
    0

    Okay, but good you have found a solution by adding the extra if statement.

    But i´m glad that I could help you on the right track even if it took some posts to get on the right track :-)

    /Dennis

  • Kate 267 posts 610 karma points
    Oct 07, 2013 @ 23:49
    Kate
    1

    Thanks again.

    if I ever finds out what the right solution is I will post it :-)

Please Sign in or register to post replies

Write your reply to:

Draft