I was hoping to find some advice on combining two elements of an umbraco website.
I am trying to pull through an image crop (which is working correctly) but I also want to include a textsting on the image so the user can enter in an external URL. The code below produces the image and the link but it is duplicating the list 3 times. What am I doing wrong here?
Also, the texstring is a property on a media item.
Thanks
@{
var children = @Model.NodeById(1302).DescendantsOrSelf();
When I move the <ul> out of the foreach loop, it stops working. I think I am struggling to understand how to combine the two results into one foreach loop. Is that even possible?
Yes it is possible. If it stops working what you could do instead when looping in your image folder container for images is to check if the textString for the image Url is empty or not.
Something like this instead
foreach(dynamic img in imgfolder.Children){ var url = (img.HasValue("yourTextStringAlias"))? @img.yourTextStringAlias : ""; <li><a href="@url" title="test" target="_blank"><img src="@d.Crops.logoCrop" alt="@d.Alt" /></a></li> }
so I have tried to impement your suggested code but it does not seem to work. This im sure is down to my error as I am completely new to razor!
The logoCarousel is a document type set on a page, where as the url is contained on the media file. So i think when I loop inside the logoCarousel which contains a media file containing the property logoLink, it is somehow not finding the media property.
@{
if(Model.logoCarousel.Count > 0){
<ul id="mycarousel" class="jcarousel-skin-tango">
@foreach(dynamic d in Model.logoCarousel)
{
var url = (d.HasValue("logoLink"))? @d.yourTextStringAlias : "";
Combing media items with a property
Hello,
I was hoping to find some advice on combining two elements of an umbraco website.
I am trying to pull through an image crop (which is working correctly) but I also want to include a textsting on the image so the user can enter in an external URL. The code below produces the image and the link but it is duplicating the list 3 times. What am I doing wrong here?
Also, the texstring is a property on a media item.
Thanks
@{
var children = @Model.NodeById(1302).DescendantsOrSelf();
foreach (var item in @children) {
if(Model.logoCarousel.Count > 0){
<div>
<ul id="mycarousel" class="jcarousel-skin-tango">
@foreach(dynamic d in Model.logoCarousel)
{
var link = @Model.NodeById(1302);
<li><a href="http://@item.logoLink" title="test" target="_blank"><img src="@d.Crops.logoCrop" alt="@d.Alt" /></a></li>
}
</ul>
</div>
}
}
}
Hi,
Looks like you are looping your <ul id="mycarousel" class="jcarousel-skin-tango">.
Thanks for your response.
When I move the <ul> out of the foreach loop, it stops working. I think I am struggling to understand how to combine the two results into one foreach loop. Is that even possible?
Yes it is possible. If it stops working what you could do instead when looping in your image folder container for images is to check if the textString for the image Url is empty or not.
Something like this instead
so I have tried to impement your suggested code but it does not seem to work. This im sure is down to my error as I am completely new to razor!
The logoCarousel is a document type set on a page, where as the url is contained on the media file. So i think when I loop inside the logoCarousel which contains a media file containing the property logoLink, it is somehow not finding the media property.
@{
if(Model.logoCarousel.Count > 0){
<ul id="mycarousel" class="jcarousel-skin-tango">
@foreach(dynamic d in Model.logoCarousel)
{
var url = (d.HasValue("logoLink"))? @d.yourTextStringAlias : "";
<li><a href="@url" title="test" target="_blank"><img src="@d.Crops.logoCrop" alt="@d.Alt" /></a></li>
}
</ul>
}
}
and I receive an error relating to DAMP;
'DAMP.RazorModel.DAMP_Item' does not contain a definition for 'HasValue'
is working on a reply...