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
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.
Recursiv images
Hi
Is there anyone who can help get the pictures recursiv?
Here is what I got so fare:
Hi Kate,
I do it this way and the logo is set on the homepage node i my case.
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
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
Hi Dennis
I can't get it to work :-(
I have tried this:
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.
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
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.
/Dennis
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.
Hi Kate,
Try this one:
Just heightligted the difference with bold. I remove the @ sign in the variable.
/Dennis
When I write it like this, it works. But I have to have this ekstra if-sentens
any good explanation??
Nope I don´t have an good explanation for that.
But have you tried to see if you could write it shorter by this:
Without the if statement. I don´t know if it actually will work.
/Dennis
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 :-)
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
Sorry, it still gives me an error: "The name 'media' does not exist in the current context"
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
Thanks again.
if I ever finds out what the right solution is I will post it :-)
is working on a reply...