I tried to use two if statements into foreach such as this but I get this error:
Encountered end tag "div" with no matching start tag. Are your
start/end tags properly balanced?
I want this to be the condition: If the variable i is smaller than the one I want to be the part of this code inside a div element with row class.
<text>
<div class="col-xs-2 col-wrapper">
<div class="image-wrapper">
<img src="#Url.Content(path + item.PhotoName)" alt="" />
<img class="delimg" src="~/Content/Adminex/images/delete-icons.png" id="#item.Id" />
</div>
</div>
</text>
.Please advice,
#{
string path = System.Configuration.ConfigurationManager.AppSettings["ImageEdit"];
int i = 0;
}
#foreach (var item in Model.PhotoTables)
{
if (i == 7)
{
i = 0;
}
if (i < 1)
{
#:<div class="row">
}
<text>
<div class="col-xs-2 col-wrapper">
<div class="image-wrapper">
<img src="#Url.Content(path + item.PhotoName)" alt="" />
<img class="delimg" src="~/Content/Adminex/images/delete-icons.png" id="#item.Id" />
</div>
</div>
</text>
if (i < 1)
{
#:</div>
}
i++;
}
That </div> above i++ looks suspiciously lonesome.
EDIT:
Now I think I understand, you want 7 text items each in each div row (with any remainder in the last row). Here's one of many ways..
#foreach (var item in Model.PhotoTables) {
if (i < 1) {
#:<div class="row">
}
<text>
...item...
</text>
i++;
if (i == 7) {
i = 0;
#:</div>
}
}
if (i > 0) {
#:</div>
}
That produces this, if that's what you want..
<div class="row">
<text>..1..</text>
<text>..2..</text>
<text>..3..</text>
<text>..4..</text>
<text>..5..</text>
<text>..6..</text>
<text>..7..</text>
</div>
<div class="row">
<text>..8..</text>
</div>
If I am not wrong, you want to wrap text tag in <div class="row"> when i < 1. So you can try this. It works for me.
#{
string path = System.Configuration.ConfigurationManager.AppSettings["ImageEdit"];
int i = 0;
}
#foreach (var item in Model.PhotoTables)
{
if (i == 7)
{
i = 0;
}
if (i < 1)
{
<div class="row">
<text>
<div class="col-xs-2 col-wrapper">
<div class="image-wrapper">
<img src="#Url.Content(path + item.PhotoName)" alt="" />
<img class="delimg" src="~/Content/Adminex/images/delete-icons.png" id="#item.Id" />
</div>
</div>
</text>
</div>
}
else
{
<text>
<div class="col-xs-2 col-wrapper">
<div class="image-wrapper">
<img src="#Url.Content(path + item.PhotoName)" alt="" />
<img class="delimg" src="~/Content/Adminex/images/delete-icons.png" id="#item.Id" />
</div>
</div>
</text>
}
i++;
}
I think this will do the trick. use the modulus operator to find out if you are at the beginning or at the end of counting to 7 and if the items are not up to 7 the closing div will still be in place
#{
string path = System.Configuration.ConfigurationManager.AppSettings["ImageEdit"];
int i = 0;
int modelCount = Model.PhotoTables.Count();
}
#foreach (var item in Model.PhotoTables)
{
//if (i == 7)
// {
// i = 0;
// }
if (i % 6 == 0)
{
#:<div class="row">
}
<text>
<div class="col-xs-2 col-wrapper">
<div class="image-wrapper">
<img src="#Url.Content(path + item.PhotoName)" alt="" />
<img class="delimg" src="~/Content/Adminex/images/delete-icons.png" id="#item.Id" />
</div>
</div>
</text>
if (i % 6 == 5 || i == modelCount - 1)
{
#:</div>
}
i++;
}
Related
I am trying to remove item using ng-if and ng-else-if.
"ng-if="navItem.gbn.indexOf('12345') !== -1" is true then array item only show contains('12345') items.
but the item still remain in array so I think ng-else-if is not working.
I don't know how to delete it.
I have the following Angular code:
<div ng-controller="PIDAEController">
<div class="container-fluid" style="padding-top:30px;">
<div class="row">
<div class="col-lg-2 col-md-3 col-xs-6 tubmbimg" ng-repeat="navItem in navItems | Fpage: curPage * pageSize | limitTo:pageSize" ng-if="navItem.gbn.indexOf('12345') !== -1">
<a class="thumbnail border" href="#/item/{{navItem.site}}">
<div class="b-marjin">
<span align="center" class="label label-primary full-width" >{{ navItem.gbn }}</span>
</div>
<div>
<img style="border: 1px solid black;" class="img-responsive full-width" src="{{navItem.pimg}}" alt="">
</div>
<div align="center" class="under-block">
<span title="{{ navItem.pname }}" align="center">{{ navItem.pname2}}</span>
</div>
</a>
</div>
<div ng-else-if="navItems.splice(navItem, 1)"></div>
</div>
</div>
</div>
angular.forEach(item, function (value, key) {
var keepGoing = true;
if(keepGoing) {
if(value.gbn.indexOf("11600") != -1) {
$scope.initialized = true;
$scope.navItems = item;
$scope.curPage=0;
$scope.pageSize=20;
$scope.numberOfPage = Math.ceil(item.length / $scope.pageSize);
keepGoing = false;
}
else {
$scope.navItems.splice(key, 1);
}
}
});
ng-else-if does NOT EXIST. its neither angular or angularJS.
In the line
<div ng-else-if="navItems.splice(navItem, 1)"></div>
splice requires navItem to be an index/int, not an object.
As an alternative to ng-else-if you can simply do:
ng-if="navItem.gbn.indexOf('12345') == -1
Also, splice would return the removed array item when found, not sure if "ng-if" handles that as being TRUE.
I have figured out a way to dynamically insert child elements into a specific parent div element based on the status property from the model. The problem with my version is that I am using 4 loops to achieve this. Is there a better way to achieve this? like 1 loop.
Here is my code:
<div class="col-lg-3">
#foreach (var item in Model)
{
if (item.Status == OrderStatus.New)
{
<div class="order"></div>
}
}
</div>
<div class="col-lg-3">
#foreach (var item in Model)
{
if (item.Status == OrderStatus.Preparing)
{
<div class="order"></div>
}
}
</div>
<div class="col-lg-3">
#foreach (var item in Model)
{
if (item.Status == OrderStatus.Delivering)
{
<div class="order"></div>
}
}
</div>
<div class="col-lg-3">
#foreach (var item in Model)
{
if (item.Status == OrderStatus.Delivered)
{
<div class="order"></div>
}
}
</div>
</div>
As you can see that I am adding a bunch of div tags into one of the 4 columns based on the status. I am using a loop for each one to achieve this.
Just take this loop outside of this elements and check if item has expected status. Is this what are you looking for?
#foreach(var item in Model)
{
<div class="col-lg-3">
if (item.Status == OrderStatus.New)
{
<div class="order"></div>
}
</div>
<div class="col-lg-3">
if (item.Status == OrderStatus.Preparing)
{
<div class="order"></div>
}
</div>
<div class="col-lg-3">
if (item.Status == OrderStatus.Delivering)
{
<div class="order"></div>
}
</div>
<div class="col-lg-3">
if (item.Status == OrderStatus.Delivered)
{
<div class="order"></div>
}
</div>
}
</div>
Edited version:
#foreach(var item in Model)
{
if (item.Status == OrderStatus.New)
{
<div class="col-lg-3">
<div class="order"></div>
</div>
}
if (item.Status == OrderStatus.Preparing)
{
<div class="col-lg-3">
<div class="order"></div>
</div>
}
if (item.Status == OrderStatus.Delivering)
{
<div class="col-lg-3">
<div class="order"></div>
</div>
}
if (item.Status == OrderStatus.Delivered)
{
<div class="col-lg-3">
<div class="order"></div>
</div>
}
}
</div>
Add break to your consition like below:
<div class="col-lg-3">
#foreach (var item in Model)
{
if (item.Status == OrderStatus.New)
{
<div class="order"></div>
break;
}
}
</div>
<div class="col-lg-3">
#foreach (var item in Model)
{
if (item.Status == OrderStatus.Preparing)
{
<div class="order"></div>
break;
}
}
</div>
<div class="col-lg-3">
#foreach (var item in Model)
{
if (item.Status == OrderStatus.Delivering)
{
<div class="order"></div>
break;
}
}
</div>
<div class="col-lg-3">
#foreach (var item in Model)
{
if (item.Status == OrderStatus.Delivered)
{
<div class="order"></div>
break;
}
}
</div>
I am trying to change the image by clicking on it.
I have written the codes and it's not working.
<div class="img fadeIn" >
<img src="logo.png" height="90px" width="320px" onclick="change()" id="koo" />
</div>
JavaScript code:
function change() {
var mySrc = this.getAttribute('src');
if( mySrc == 'logo.png' ){
this.setAttribute('src','logo1.png');
} else {
this.setAttribute('src','logo.png');
}
}
You have to put the element as an argument to the function.
I have attached the working code.
function change(t) {
var mySrc = t.getAttribute('src');
if( mySrc == 'logo.png' ){
t.setAttribute('src','logo1.png');
t.setAttribute('alt','logo1');
} else {
t.setAttribute('src','logo.png');
t.setAttribute('alt','logo');
}
}
<div class="img fadeIn" >
<img src="logo.png" height="90px" width="320px" onclick="change(this)" id="koo" alt="logo"/>
</div>
There is also a way to do this. Please refer to the code
<div class="img fadeIn">
<img src="logo.png" height="90px" width="320px" onclick="change()" id="koo" />
</div>
function change() {
var imgTag = event.target;
var mySrc = imgTag.getAttribute('src');
if( mySrc == 'logo.png' ){
imgTag.setAttribute('src','logo1.png');
} else {
imgTag.setAttribute('src','logo.png');
}
}
Try This!
var ele = document.getElementById("koo");
ele.addEventListener('click',function(){
var src = (ele.getAttribute('src') == "logo.png")?"logo1.png":"logo.png";
ele.setAttribute('src',src);
})
<div class="img fadeIn" >
<img src="logo.png" height="90px" width="320px" id="koo" />
</div>
I'm trying to create rows dynamically with razor but I can't figure out how to wrap this around. What I want is for every 5:e object in my model I want to create a new row/div <div class="row pics_in_a_row"> so that each row contains five or less images.
<section class="slice">
<div class="wp-section">
<div class="container">
<div class="row pics_in_a_row">
#{
int i = 0;
foreach (dbphoto.Models.Image s in Model.images.OrderByDescending(x => x.idimage))
{
if (i % 5 == 0 && i != 0)
{
<br />
}
i++;
if (1 == 1)
{
<div class="flxbox" style="flex: calc(1024/713)">
<a href="#s.HighResolution" data-fancybox="gallery" data-caption="xyz, Stockholm">
<img src="#s.LowResolution" class="img-fluid rounded flximg" />
</a>
</div>
}
}
}
</div>
</div>
</div>
</section>
Bonus question: how can I get the height and width of the image and add it to the calc() css?
You should add the div with class row pics_in_a_row inside your loop
This should create a a row for every 5 items (or less for the last row when the remaining items are less than 5).
<div class="container">
#{
var numberOfColsNeeded = 5;
var totalCounter = Model.images.Count();
var itemCounter = 1;
}
#foreach (var item in Model.images)
{
if (itemCounter % numberOfColsNeeded == 1)
{
#:<div class="row pics_in_a_row">
}
<div class="flxbox" style="flex: calc(1024 / 713)">
<img src="#item.LowResolution" class="img-fluid rounded flximg" />
</div>
if ((itemCounter % numberOfColsNeeded == 0) || ((itemCounter) == totalCounter))
{
#:</div>
}
itemCounter++;
}
</div>
I have 3 sets of images in 3 separate divs that are hard coded into the webpage. Only one set is viewed at a time by user choice button. This was ok when there were only 5 images in each set but now that I added more, the page is loading so slowly. The pictures are 1200 by 900 px because I am using nivo-slider which allows sizing.
Is there a way to load only the picture set that is clicked?
<div class="slider-wrapper theme-default" id="wrapper1" >
<div class="nivoSlider" id="c1" >
<img src="images/Germany2008/GermanyTrip01.jpg" alt="" />
<img src="images/Germany2008/GermanyTrip02.jpg" alt="" />
<!--etc. -->
</div>
</div>
<div class="slider-wrapper theme-default" id="wrapper2" >
<div class="nivoSlider" id="c2">
<img src="images/Germany2008/GermanyTrip01.jpg" alt="" />
<img src="images/Germany2008/GermanyTrip02.jpg" alt="" />
<!--etc. -->
</div>
</div>
Thank you.
I'm not perfectly clear on what you want but I'll try.
Add the following javascript at the bottom of the body:
var wrapperOneImages = ["path/to/image","path/to/image","path/to/image"];
var wrapperTwoImages = ["path/to/image","path/to/image","path/to/image"];
var amountOfWrappers = 2;
for (i=0; i < amountOfWrappers; i++) {
var nivoSlider = document.createElement("div");
nivoSlider.setAttribute("class", "nivoSlider");
nivoSlider.setAttribute("id", "c" + toString(i+1));
var wrapper = document.getElementById("wrapper" + toString(i+1));
if (i == 0) {
var whatWrapper = wrapperOneImages;
} else if (i == 1) {
var whatWrapper = wrapperTwoImages;
}
for (j=0; j < whatWrapper.length; j++) {
var img = document.createElement("img");
var img.setAttribute("src", whatWrapper[j]);
nivoSlider.appendChild(img);
}
wrapper.appendChild(nivoSlider);
}
And replace all of the html you provided with the following:
<div class="slider-wrapper theme-default" id="wrapper1" ></div>
<div class="slider-wrapper theme-default" id="wrapper2" ></div>
I haven't tested it but it should work.