I hope you can help me. I am currently incporating the uBlogsy platform into a website that encompasses standard Umbraco pages along with a Foum and the blog platform, but I need some assistance with referencing user uploaded images within the uBlogsyHomeShowPost.cshtml file.
I have amended the showlists file so that key articles will appear on the home page and along with that I have also amended the Blog Post template and document types to include an image that will be used both within the post itself and as a teaser image on the home page.
I have been able to easily resolve the style and placement issues of all the requried text but I cannot see how to reference the image (alias of featuredImage) within the cshtml file.
It's kind of difficult to find information about using images for some reason. I know I had problems finding it when I was starting out. Anyway, here is hopefully what you need (if you scroll to the bottom):
Cheers for that Trond.. Fair point, for reference I am using 4.8.0
One more question if possible :)
The article references the code below as the solution (just the one version), where the alias for my file will be featuredImage would that go in place of 'mainImage'? I have already tried several versions and not quite working, but as long as I know I'm on teh right track I'm happy to play around with the code.
Cheers again
Example of the option I intend to use
@{ if (Model.HasValue("mainImage")){ <img src="@Model.Media("mainImage","umbracoFile")" width="@Model.Media("mainImage","umbracoWidth")" height="@Model.Media("mainImage","umbracoHeight")" /> } }
Still not working but I'm pretty sure that it is the datatype that is causing the issue now...Mainly because I know nothing about them!!!! :P
Is this something I can do within Umbraco itself? keep in mind that I am predominantly a front end designer who has basically messed around with cshtml files for the first time yesterday
An umbraco page consists of 3 elements, the template (layout, html), the document type (metadata about the contents of the page) and the page contents itself.
featuredImage is described in the document type, its a property. Properties can be of different types; text, image, links etc. The different types are called Data Types.
Hm, its probably confusing :) Its actually not so complicated, you should probably watch atleast the first (free) video on umbraco.tv about document types first...
That all makes sense. i have been working with umbraco for around 6 months now although predominantly 90% front end and XSLT manipulation. until this project I had never looked at the cshtml files at all so all a bit daunting!! I love the felxibility of multiple templates and doc types etc...
From your comments above I had 'featuredImage' as the alias to a media type, so I shouldn't need to do anything else re the datatypes should I?
Bizarre, just tried that and along with all the other text I found the following
item
Start parsing 'mainImage'
1.35299227850242
0.001746
item
Done parsing 'mainImage'
So as far as I can tell it worked fine... so, the problem isn't with the cshtml code then by the looks of it! I'm including this as part of the Ublogsy platform so I wonder if I am using the incorrect Doc type!?
Very frustrating!
Cheers for all your help chap, really appreciate it.
Wasn't that supposed to be featuredImage instead of mainImage? Note that if you give a non-existing property name to Umbraco it will happily ignore it (no errors, and no output) - by design. So you get no errors?
I'm usually using a Content Picker data type for images as this allows the editor to choose the image from the media library. The content picker data type will return the ID of the selected image. You can check Data type on the pages Document type under the 'generic properties' tab (Settings section of backoffice).
(If you're not sure about which document type it is, you can find it in the 'Properties' tab after selecting the page in the Content Section of Umbraco)
Just to let you know that I got the code to work but not in teh region that I wanetd to! Looks like the issue is with my udnerstanding of the UBlogsy set up rather than the code itself!!
Help with basic cshtml and image use
Hi guys,
I hope you can help me. I am currently incporating the uBlogsy platform into a website that encompasses standard Umbraco pages along with a Foum and the blog platform, but I need some assistance with referencing user uploaded images within the uBlogsyHomeShowPost.cshtml file.
I have amended the showlists file so that key articles will appear on the home page and along with that I have also amended the Blog Post template and document types to include an image that will be used both within the post itself and as a teaser image on the home page.
I have been able to easily resolve the style and placement issues of all the requried text but I cannot see how to reference the image (alias of featuredImage) within the cshtml file.
Any thoughts guys!!??
It's kind of difficult to find information about using images for some reason. I know I had problems finding it when I was starting out. Anyway, here is hopefully what you need (if you scroll to the bottom):
http://our.umbraco.org/documentation/Using-Umbraco/Backoffice-Overview/Property-Editors/Built-in-Property-Editors/Media-Picker
ps. you should always state which version of Umbraco you're using, the solutions can be different for different versions.
Hey there,
Cheers for that Trond.. Fair point, for reference I am using 4.8.0
One more question if possible :)
The article references the code below as the solution (just the one version), where the alias for my file will be featuredImage would that go in place of 'mainImage'? I have already tried several versions and not quite working, but as long as I know I'm on teh right track I'm happy to play around with the code.
Cheers again
Example of the option I intend to use
Hi,
Yes, featuredImage should be used instead of mainImage.
It is case-sensitive so be careful with spelling, it is also assumed that featuredImage is a Media Picker data type.
It might be helpful to take a look at the razor cheat sheet.
Thanks again,
Still not working but I'm pretty sure that it is the datatype that is causing the issue now...Mainly because I know nothing about them!!!! :P
Is this something I can do within Umbraco itself? keep in mind that I am predominantly a front end designer who has basically messed around with cshtml files for the first time yesterday
Cheers for all your help to date Trond :)
An umbraco page consists of 3 elements, the template (layout, html), the document type (metadata about the contents of the page) and the page contents itself.
featuredImage is described in the document type, its a property. Properties can be of different types; text, image, links etc. The different types are called Data Types.
Hm, its probably confusing :) Its actually not so complicated, you should probably watch atleast the first (free) video on umbraco.tv about document types first...
Cheers Trond,
That all makes sense. i have been working with umbraco for around 6 months now although predominantly 90% front end and XSLT manipulation. until this project I had never looked at the cshtml files at all so all a bit daunting!! I love the felxibility of multiple templates and doc types etc...
From your comments above I had 'featuredImage' as the alias to a media type, so I shouldn't need to do anything else re the datatypes should I?
Hi again Trond,
Apologies, still getting no joy with this code! Can you see any issue with the code below (the new code is in bold)
@using uBlogsy.Common.Extensions;
@using uBlogsy.Common.Helpers;
@using umbraco.MacroEngines;
@using uBlogsy.BusinessLogic;
@{
DynamicNode d;
if (PageData.Count > 0){
d = new DynamicNode(PageData[0]);
}
else{
d = new DynamicNode(Model.Id);
}
<div class="uBlogsy_post uBlogsy_bottom_border">
@{
if (Model.HasValue("mainImage")){ <img src="@Model.Media("mainImage","umbracoFile")" width="@Model.Media("mainImage","umbracoWidth")" height="@Model.Media("mainImage","umbracoHeight")" />
}
}
<h3>
<a href="@d.Url" title="@d.GetProperty("uBlogsyContentTitle")"><span>@d.GetProperty("uBlogsyContentTitle")</span></a></h3>
<div id="mainartp">
<p>@d.GetProperty("uBlogsyContentSummary")</p>
</div>
</div>
}
@helper RenderPostBody(DynamicNode d)
{
string useSummary = DataService.Instance.GetValueFromLanding(Model.Id, "uBlogsyGeneralUseSummary");
if (useSummary == "1"
&& Model.NodeTypeAlias == "uBlogsyLanding"
&& d.GetProperty("uBlogsyContentSummary").Value.Trim() != string.Empty
)
{
@Html.Raw(d.GetProperty("uBlogsyContentSummary").Value)
}
else
{
@Html.Raw(umbraco.library.RenderMacroContent(d.GetProperty("uBlogsyContentBody").Value, d.Id))
}
}
Have tried to resolve myself with the assistance you have already kindly provided but feel I need some more direct intervention!
Hmm, there is nothing obviously wrong (to me atleast).
It would be much easier with the debug trace, just add ?umbDebugShowTrace=true to the end of the URL you use to access the page.
(If it doesn't work you'll have to edit the web.config file, set umbracoDebugMode to true. When going live, this value should be false )
Bizarre, just tried that and along with all the other text I found the following
So as far as I can tell it worked fine... so, the problem isn't with the cshtml code then by the looks of it! I'm including this as part of the Ublogsy platform so I wonder if I am using the incorrect Doc type!?
Very frustrating!
Cheers for all your help chap, really appreciate it.
Wasn't that supposed to be featuredImage instead of mainImage? Note that if you give a non-existing property name to Umbraco it will happily ignore it (no errors, and no output) - by design. So you get no errors?
I'm usually using a Content Picker data type for images as this allows the editor to choose the image from the media library. The content picker data type will return the ID of the selected image. You can check Data type on the pages Document type under the 'generic properties' tab (Settings section of backoffice).
(If you're not sure about which document type it is, you can find it in the 'Properties' tab after selecting the page in the Content Section of Umbraco)
Just to let you know that I got the code to work but not in teh region that I wanetd to! Looks like the issue is with my udnerstanding of the UBlogsy set up rather than the code itself!!
Thanks for your help
is working on a reply...