I am new to Razor someone wrote this script for me I would like to .edit it to include a caption which is from a textstring field called text1, text2, text3 respectively, but i have been trying for three days with no result. Any help would be appreciated.
Thanks in advance
@inherits umbraco.MacroEngines.DynamicNodeContext @functions { public string GetSlideHTML(string linkURL, string imageURL, string altText, bool newWindow) { // Function to construct and return HTML for slide string htmlstring =""; if (linkURL!="" && linkURL !=null) { htmlstring += "<a href='"+linkURL+"'"; if (newWindow == true) { htmlstring+=" target='_blank'"; } htmlstring+=">"; } if (imageURL!="" && imageURL !=null) { htmlstring+="<img src='"+imageURL+"' class='slideimage' alt='"+altText+"' />"; } if (linkURL!="" && linkURL !=null) { htmlstring += " @item.textstring</a>"; } return htmlstring; } } @{ // Create variables to be passed to the GetSlideHTML() function, then rendered below var image1URL = Library.MediaById(Model.slide1).umbracoFile; var image1Name = Library.MediaById(Model.slide1).Name; var text1Text =Model.text1.Text; var link1URL =Model.link1.Url; bool link1NewNindow = Model.link1.NewWindow; var image2URL = Library.MediaById(Model.slide2).umbracoFile; var image2Name = Library.MediaById(Model.slide2).Name; var link2URL =Model.link2.Url; bool link2NewNindow = Model.link2.NewWindow; var image3URL = Library.MediaById(Model.slide3).umbracoFile; var image3Name = Library.MediaById(Model.slide3).Name; var link3URL =Model.link3.Url; bool link3NewNindow = Model.link3.NewWindow;
I think you will need to expand the list of parameters the method GetSlideHtml is using...So I can imagine your code should look something like this
@inherits umbraco.MacroEngines.DynamicNodeContext
@functions {
public string GetSlideHTML(string linkURL, string imageURL, string altText, bool newWindow, string captionText)
{
// Function to construct and return HTML for slide
string htmlstring ="";
if (linkURL!="" && linkURL !=null)
{
htmlstring += "<a href='"+linkURL+"'";
if (newWindow == true)
{
htmlstring+=" target='_blank'";
}
htmlstring+=">";
}
if (imageURL!="" && imageURL !=null)
{
htmlstring+="<img src='"+imageURL+"' class='slideimage' alt='"+altText+"' />";
}
if(captionString !="" && captionString !=null)
{
htmlstring+="<span>captionText<span>";
}
if (linkURL!="" && linkURL !=null)
{
htmlstring += " @item.textstring</a>";
}
return htmlstring;
}
}
@{
// Create variables to be passed to the GetSlideHTML() function, then rendered below
var image1URL = Library.MediaById(Model.slide1).umbracoFile;
var image1Name = Library.MediaById(Model.slide1).Name;
var text1Text =Model.text1.Text;
var link1URL =Model.link1.Url;
bool link1NewNindow = Model.link1.NewWindow;
var image2URL = Library.MediaById(Model.slide2).umbracoFile;
var image2Name = Library.MediaById(Model.slide2).Name;
var text2Text = Model.text2.Text;
var link2URL =Model.link2.Url;
bool link2NewNindow = Model.link2.NewWindow;
var image3URL = Library.MediaById(Model.slide3).umbracoFile;
var image3Name = Library.MediaById(Model.slide3).Name;
var text3Text = Model.text3.Text;
var link3URL =Model.link3.Url;
bool link3NewNindow = Model.link3.NewWindow;
}
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script src="/scripts/jquery.flexslider-min.js"></script>
<script type="text/javascript">
$(window).load(function() {
$('.flexslider').flexslider({
animation: "fade"
});
});
</script>
<div class="flexslider">
<ul class="slides">
<li>@Html.Raw(GetSlideHTML(link1URL,image1URL,image1Name,link1NewNindow,text1Text))</li>
<li>@Html.Raw(GetSlideHTML(link2URL,image2URL,image2Name,link2NewNindow,text2Text))</li>
<li>@Html.Raw(GetSlideHTML(link3URL,image3URL,image3Name,link3NewNindow,text3Text))</li>
</ul>
</div>
I have expanded the GetSlideHTml with a "caption" parameter, which I then check if is empty or null - If it's not then I wrap it in a . Finally I have added the text variables and added them as the last parameters in the list element.
Thanks for trying to help the above does not work it's throwing an error that captionString does not exist in thsiis context and if I change it to captionText it saved but then cannot load the macro is there not a way to edit this bit (in bold) to render the alt (the title of each media file) or title text. I have tried all sorts like @node.Name but have no idea how to write it and couldn't find anything that was written in a similar way.
Adding text field to a slider
Hi there
I am new to Razor someone wrote this script for me I would like to .edit it to include a caption which is from a textstring field called text1, text2, text3 respectively, but i have been trying for three days with no result. Any help would be appreciated.
Thanks in advance
Hi Natasha and welcome to our :)
I think you will need to expand the list of parameters the method GetSlideHtml is using...So I can imagine your code should look something like this
I have expanded the GetSlideHTml with a "caption" parameter, which I then check if is empty or null - If it's not then I wrap it in a . Finally I have added the text variables and added them as the last parameters in the list element.
I hope this makes sense, works and helps :)
/Jan
Hi Jan
Thanks for trying to help the above does not work it's throwing an error that captionString does not exist in thsiis context and if I change it to captionText it saved but then cannot load the macro is there not a way to edit this bit (in bold) to render the alt (the title of each media file) or title text. I have tried all sorts like @node.Name but have no idea how to write it and couldn't find anything that was written in a similar way.
Thanks again
Natasha
}
is working on a reply...