In my Umbraco 7.15.7 I'm displaying images in the Partial Views Macro Files as follow:
figure>
#if (newsItem.HasValue("articleImg"))
{
<img src="#Umbraco.Media(newsItem.articleImg.ToString()).Url" class="img-fluid news-img" alt="#newsItem.Last().photoAlt" />
}
(the reason for the .ToString() is after I switched from Obsolete to Media.Picker2 - so since it's string)
In my Umbraco 11.1 I was struggle to display the images. I tried the following and it didn't display the images, but also didn't throw an error, just didn't display the images:
<img src="#Umbraco.Media(newsItem.Value<IPublishedContent>("articleImg").ToString()).Url()" class="img-fluid" alt="#Imaging_pagesToList.Last().Value("photoAlt")" />
So I tried this one:
<img src="newsItem.Value<IPublishedContent>("articleImg").Url()" class="img-fluid" alt="#newsItem.Value("photoAlt")" />
And this one also doesn't show any image
I also tried this one (the same as above, just with # - #newsItem) , and this throw an error: "Argument 3: cannot convert from 'method group' to 'object?'":
<img src="#newsItem.Value<IPublishedContent>("articleImg").Url()" class="img-fluid" alt="#newsItem.Value("photoAlt")" />
So I tried this one:
var image = newsItem.Value<IPublishedContent>("articleImg");
<img src="#image.Url()" class="img-fluid" alt="#newsItem.Value("photoAlt")" />
And this is finally works! And I don't understand why? (why this works, and why the previous didn't work)
My question are:
Why only the last one works?
Why the first two doesn't work?
Is this is the right way to render images in Umbraco 11.1 ?
In the official documentations of Umbraco (9 and up) they suggest to render images as follow:
var mediaItem = Umbraco.Media(Guid.Parse("55240594-b265-4fc2-b1c1-feffc5cf9571"));
But they hard coding the Guid in their examples.
Not sure how to get the Guid for each node.
Please advise.
Thanks.
Please check what property editor is used; maybe it's a collection and not a single media. In that case, you will need something like:
newsItem.Value<IEnumarable<IPublishedContent>>("articleImg").First().Url()
Related
In view I want to show image which is store in view folder named Errorpage.png. Now, I want to show that image in Error.cshtml view file.
Here is my code
<img src="~/Views/Errorpage.png" alt="error">
Now , this code is not working and showing error alt in the place of image. While the path is perfectly right, but surprised that why it is not working.
While I tried by fetch the online image and that is work.
Here is the code
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/4273/anton-ploom.jpg"
alt="A danseur in brisé (a leap with the legs together) on a blue background">
Now, I am confused that this second code is working properly while the first code is not working.
The syntax is same both of the code.
Thank You.
Try with this way:
can you please put your image in image folder outside Views folder
that can work
or
<img alt="error" src="#Url.Content("/Views/Errorpage.png")" />
if that doesn't work you could try with this way:
<img alt="error" src="/Views/Errorpage.png" />
or there is another solution if all are fails :
<img alt="error" src="<%= Url.Content("~/Views/Errorpage.png") %>" />
in visual studio, the image works from ~/contents/*.jpeg directory.
if you will put it in any other directory it will not work.
try this
<img src="#Url.Content("~/Views/Errorpage.png")" alt="error"/>
I'm trying to use data-interchange from Foundation 5 with slim as follows:
= image_tag('', 'data-interchange' => "[#{image_path('umed-image-large.jpg')}, (medium)], [#{image_path('umed-image-small.jpg')}, (small-only)]")
The problem is that it works the first time when loading the page but when clicking on a logo in the nav bar (the url is the same), the image is no more displaed. I observed the generated HTML in the Chrome console when the image is displayed:
<img data-interchange="[/assets/umed-image-large-45e4ffd1823f658bf167972ba4a8cad74797963d9a8906f65a8710d1c7458145.jpg, (medium)], [/assets/umed-image-small-97b7dfa3c6ca88e76b355eece97b723f458ae455f501013d1b0084ce0f5bd953.jpg, (small-only)]" src="/assets/umed-image-large-45e4ffd1823f658bf167972ba4a8cad74797963d9a8906f65a8710d1c7458145.jpg" data-uuid="interchange-j30j01nh0">
And here is the HTML when there is no image:
<img data-interchange="[/assets/umed-image-large-45e4ffd1823f658bf167972ba4a8cad74797963d9a8906f65a8710d1c7458145.jpg, (medium)], [/assets/umed-image-small-97b7dfa3c6ca88e76b355eece97b723f458ae455f501013d1b0084ce0f5bd953.jpg, (small-only)]" src="">
As you see, there is no src data in the latter case. Any idea what is wrong here ? Thank you.
Using MVC 5 Razor Views.
I currently have a link to open a document that sits on the server in my about view as follows........
Basic Training <img src="~/Content/Images/Word.jpg" height="24" width="24" />
What I'd like is to be able to have a link to open this document at a particluar bookmark.
From what I have read so far, it would seem that the bookmark is specified after a # symbol. Unfortunately it doesn't seem to work and the document just opens from the start.
I've tried opening via an action using the #' notation as werll, but as yet, no joy.
FileStream fs = new FileStream(Server.MapPath(#"~\Content\My Doc - Basic Training.docx"), FileMode.OpenOrCreate, FileAccess.ReadWrite);
return File(fs, "My Doc - Basic Training.docx");
I've simply been appending #BoomarkName to the filename. No joy as of yet.
Is it possible?
If so could someone please point me in the right direction.
Just seems to work with #bookmark_name, as explained in How to create a hyperlink from an HTML page to a bookmark in Word.
So:
Basic Training <img src="~/Content/Images/Word.jpg" height="24" width="24" />
I have (java) code that generates PNG images from a custom infrared camera from time to time all the same size and, at the moment, just saves them outside the server space. They all have the same name and the most recent overwrites the previous one.
I can send a message to my dart code in the browser that an image is available for automatic loading for display in an image element.
Should I create an image folder and save them there?
How would the browser request and display the image? I'm using port 4955 for html.
I'm new at dart, html etc.
<-- edit -->
Will this allow me to change the DOM?
HTML
<div id='image-div'>
<img alt='' id='image' src='resources/200C-B12.png'
height='480' width='640'>
</div>
CSS
#image {
}
Dart
ImageElement imageElement = querySelector('#image');
I think I want to change the above ImageElement to this the below but don't know how.
"<img alt='' id='image' src='imageDisplay/myimage.png'
height='480' width='640'>";
<-- edit -->
I have tried the suggested methods to request the image but none works. The most recent attempt is below. I have a statement that writes to a log-file in the Dart server code that handles HTTP requests and, while there are log entries made when the page page is loaded there are none when I try to request a different image. The client page does receive the correct path to the image so the problem is that I still don't grok the correct procedure.
HTML currently - want to replace src ... to src='displayImage/some_image.png'
<div id='img-box'>
<div id='image-div'>
<div id='imgAnchor'>
<img alt='' id='image' src='resources/fi_12_demo.png'
height='480' width='640'>
</div>
</div>
</div>
Dart code fragment:
void displayNewImage(imagename) {
updateLog('display image = $imagename'); // imagename is correct
var anchor = querySelector('#imgAnchor');
anchor.children.clear;
anchor.append(new ImageElement()
..innerHtml="<img alt='' id='image' src='$imagename' height='480px' width='640px'>");
}
I conclude that no request is being sent from the client to my Dart server.
I think adding an <img src="http://yourserver.yourdomain.com:4955/somefolder/someimg.png"> to your HTML dynamically (by Dart code) should do. If the updated images have the same name you might run into caching issues (the browser doesn't load the image from the server but loades it from the cache instead). It might be easier to store each image with a new name.
I have a getResources call that shows 6 items on my homepage:
[[!getResources?
&tpl=`homepageInventoryCellTpl`
&parents=`4`
&resources=`-33`
&depth=`10`
&limit=`6`
&includeContent=`1`
&includeTVs=`1`
&processTVs=`0`
&hideContainers=`1`
&showHidden=`1`
&debug=`0`
&sortbyTV=`vehicleonhomepage`
&sortDirTV=`DESC`
]]
it does work showing 6 thumbs [for vehicles] but it shows the same thumb for each vehicle!
The output tag looks like:
<img class="img-responsive"
src="
[[!phpthumbof?
&input=`[[!++gallery.files_url]][[!getgalleryAlbumCover?
&id=`[[!+tv.vehiclegallery]]`]]`
&options=`&w=300`
]]"
/>
Note that nothing is cached [!]
getResources does work correctly and returns six different images if I remove the phpthumbof bit
I've cleared all the different caches several times
[[!++gallery.files_url]] just returns the gallery path [/assets/gallery/]
[[!getgalleryAlbumCover? &id=`[[!+tv.vehiclegallery]] returns the actual name of the album cover
the /assets/components/gallery/cache/ directory is writable.
Why is it showing the same thumb for all 6 vehicles?
I had the same problem. In the end I removed phpPhumbOf and installed pThumb and problem disapeared.