Umbraco, displaying images from the media picker in child nodes - umbraco

I have a products view which should display some products. The ProductItem is a child node of Products and has a property of productImage, which is a media picker. I have two ProductItem and have assigned one image each in the media picker, but I'm having trouble rendering them on the site.
#inherits Umbraco.Web.Mvc.UmbracoViewPage<ContentModels.Products>
#using ContentModels = Umbraco.Web.PublishedModels;
#{
Layout = "Master.cshtml";
var products = Umbraco.Content(Guid.Parse("2740e0b9-caf3-435a-89c5-982ed890e6bd"))
.ChildrenOfType("ProductItem")
.Where(x => x.IsVisible())
.OrderByDescending(x => x.CreateDate);
}
#foreach (var product in products)
{
<section class="page-section">
<div class="container">
<div class="product-item">
<div class="product-item-title d-flex">
<div class="bg-faded p-5 d-flex ml-auto rounded">
<h2 class="section-heading mb-0">
<span class="section-heading-upper">#product.Value("productSubtitle")</span>
<span class="section-heading-lower">#product.Value("productTitle")</span>
</h2>
</div>
</div>
<img class="product-item-img mx-auto d-flex rounded img-fluid mb-3 mb-lg-0" src="" alt="">
<div class="product-item-description d-flex mr-auto">
<div class="bg-faded p-5 rounded">
<p class="mb-0">#product.Value("productContent")</p>
</div>
</div>
</div>
</div>
</section>
}
I can display the other information with no issue. I've read dozens of forum threads and documentation but I can't seem to figure out a simple solution for just displaying each products image inside of my foreach loop. I'm using the latest version of Umbraco.
ProductItem:
Assigned image:

It looks like you forget to render it in your view. The "src"attribute is empty - see attached screenshot.
Feel free to check out the Umbraco doc on how to render an image from the Media Picker at here

Related

My images wont stay on the same line, trying to use bootstrap row

My images wont stay on the same row once i put the <p> in, they both sit in there own row, not sure what im doing wrong here
<div class="container">
<div class="row">
<div class="image-fluid text-center">
<img class="bruno" src="resourcesnew/css/Img/bruno.jpg">
<p class="h6">Bruno</p>
<img class="anth" src="resourcesnew/css/Img/anth.jpg">
<p class="h6">Anthony</p>
</div>
</div>
</div>
I think whatever CSS you used in class="row" is not acting the way you expect, because that div has a single child.
I don't know what's in your css file, but the following HTML works as I expect you want:
<div class="container">
<div class="image-fluid text-center" style="display:flex">
<div>
<img class="bruno" src="resourcesnew/css/Img/bruno.jpg">
<p class="h6">Bruno</p>
</div>
<div>
<img class="anth" src="resourcesnew/css/Img/anth.jpg">
<p class="h6">Anthony</p>
</div>
</div>
</div>
Each image/text pair gets its own div, and what used to be your row div now has multiple children.

How to change Row after every N iteration in Thymeleaf?

My problem is with using thymeleaf iteration and if-else condition together.
Suppose i have 100 products in my mysql database i want to show them on a webpage using cards and there are only 4 cards in a row(I am able to print them in a row), but i want to change the row after every 4 iteration(0-3),so that new four cards will be shown in next row.
My thymeleaf Template Page:-
<div class="container" >
<div class="row">
<div class="col-xl-3" th:each="products : ${ListOfProducts}">
<div class="card" style="width: 15rem;">
<img class="card-img-top" src="..." alt="Card image cap">
<div class="card-body">
<p class="card-title" th:text = "${products.productName}"></p>
<hr>
<p class="card-text" th:text = "${products.productCost}"></p>
AddToCard
</div>
</div>
</div>
</div>
I know we can do it using loops and if-condition but i am new to thymeleaf syntax, so please help me to get out of this rid.
Thanks in advance,Your words are value for me.

3 game cards per slide in a bootstrap carousel

I have a bootstrap carousel on a page, where I have 3 game cards per one slide, but they are hardcoded. How can I make them dynamic? I need to take game cards from my db. This is what I have now:
<div id="carousel" class="carousel-inner thumb-inner">
<div class="active item">
<div class="col-lg-12 col-md-12 col-xs-12 slide1 slider-div">
<div class="game-card">Some content here</div>
<div class="game-card">Some content here</div>
<div class="game-card">Some content here</div>
</div>
</div>
<div class="item">
<div class="col-lg-12 col-md-12 col-xs-12 slide1 slider-div">
<div class="game-card">Some content here</div>
<div class="game-card">Some content here</div>
<div class="game-card">Some content here</div>
</div>
</div>
</div>
What is the right way to put a ruby code here? My thoughts were smth. like this:
<div class="active item">
<div class="col-lg-12 col-md-12 col-xs-12 slide1 slider-div">
<% Game.all.each_with_index do |game, index| %>
<div class="col-lg-4 col-md-4 col-sm-4">
<%= game.title %>
</div>
<% end %>
</div>
</div>
But this will give me all game card on a slide. What is the correct way to make 3 game card per one slide? Thanks.
You could make use of limit and offset here to get 3 records at a time. For example:
Game.offset(0).limit(3) # first 3 items
Game.offset(3).limit(3) # next 3 items
If the Game table only has a small number of records that fit comfortably in memory, you could also do something like this:
items = Game.all.to_a # do this once to load up all the records
items.shift(3) # call repeatedly to get the next 3 items
This has the advantage that you can randomise the items upfront e.g. Game.order("RANDOM()").to_a

static stacked list with no arrows

What would be the best way to do the list as in the image. When I tried doing as in the code text gets squashed into the image.
<div data-role="page" id="wrapper">
<div data-role="content">
<div class="stacked-list">
<img src="images/icon_s1.jpg" alt="Online Subscription" class="ui-li-thumb"/>
<div class="para">
<h3 class="ui-li-heading">Online Subscription</h3>
<p class="ui-li-desc">Online access to complete company profiles plus tools & analysis</p>
</p>
</div>
</div>
</div>
</div> <!-- /page -->
Image of End Result http://move.clanteam.com/images/stacked-list_08.jpg
Try list items with thumbnails?
Docs:
http://jquerymobile.com/demos/1.0a4.1/#docs/lists/lists-thumbnails.html
http://jquerymobile.com/demos/1.0a4.1/docs/lists/lists-readonly.html

PartialViews Messing With Eachother

I have the following _Layout.cshtml page that has a bunch of #Html.Action() calls to several partial views.
<div class="wrapper">
<div class="header">
<a style="text-decoration:none;" href="#Url.Action("Index", "Home")"><div class="logo"><p>fisharwe</p><span class="greenText float-right">:</span></div></a>
<div class="searchBar">
#Html.Action("Search", "Item")
</div>
<div id="hearGreenBar"></div>
</div>
<div class="pageContent">
#RenderBody()
</div>
<div class="rightColumn">
<div id="help">
<div id="allHelpContent">
<span id="helpIcon"></span> <span id="helpTitle">help</span> <span id="helpArrow"></span>
</div>
</div>
<div id="userPanel">
#if(!Request.IsAuthenticated)
{
<div id="loginForm">#Html.Action("Login", "User")</div>
<div id="registerForm">#Html.Action("Register", "User")</div>
<hr class="greyLine" />
<div id="recentlyViewedItems">
<div id="recentItemsTitle">
<span class="recentItemsIcon"></span><span class="theRecentTitle">Recently Viewed</span>
</div>
</div>
}
else
{
<div id="userInfoSummary">#Html.Action("Summary", "User")</div>
}
</div>
</div>
</div>
At the top you can see the #Html.Action("Seach", "Item") call which renders a search bar and allows users to search for items/categories/sub-categories...etc. I got this working now, but it generated a new problem! When the user searches for something, and the results are rendered, the Login and Register partials in the sidebar (userPanel) are displaying validation errors such as "Email cannot be empty". I understand that the View is rendered regardless of what partial posted back but there has to be a way to prevent that from happening... Do I have to get rid of partials and render everything into the _Layout.cshtml page? But in that case I need to make this page typed which will cause yet another issue... So what can be done? I'm open to any suggestions...
Thank you.
Do you have different forms for the search and what is in the "userPanel"?. You may want to make sure your search is doing a get and not a post.
#using (Html.BeginForm("Search", "YourController", FormMethod.Get))

Resources