Nesting a # foreach in Webmatrix 2 - webmatrix-2

I'm a tad rusty here so bear with me. I'm trying to get my list of items within their groups like so.
<h2>Category Heading 1</h2>
<ul>
<li>Item list 1</li>
<li>Item list 2</li>
</ul>
<h2>Category Heading 2</h2>
<ul>
<li>Item list 1</li>
<li>Item list 2</li>
</ul>
And my code is - I'm getting errors
#foreach (var group in db.Query(GroupName)){
<h3>#group.Name</h3>
<ul>
#foreach(var row in db.Query(queryList)){
<li> #row.title</li>
}
</ul>
}
Any help would be appreciated

You should be able to do this by getting all the data in one go and using the LINQ GroupBy operator. Here is an article I wrote about displaying hierarchical data like this: http://www.mikesdotnetting.com/Article/189/Efficiently-Displaying-Hierarchical-Data-With-The-jQuery-Accordion-In-Razor-Web-Pages
You can ignore the 2nd half where I introduce the jQuery accordion...

Related

Getting nested <li> tags also.....just need the direct <li> item

I have a page structure where it includes hyperlinks with different levels of nested list items. I am writing the xpath for just the second nested list items(level 2) but it is also giving me all the list items below level 2(level 3 or below), which i don't need. It's getting really frustrating now because I have tried different xpaths and cssSelectors, everytime it is taking the level 3 list items along with level 2.
The page structure is exactly like following:
<div>
<ul class="menuBar_menu_lvl_0">
<li class="item_lvl_1">
<li class="item_lvl_1">
<ul class="menu_lvl_1">
<li class="item_lvl_2"></li>
<li class="item_lvl_2"></li>
<li class="item_lvl_2">
<ul class="menu_lvl_2">
<li class="item_lvl_3"></li>
<li class="item_lvl_3"></li>
<li class="item_lvl_3"></li>
</ul>
</li>
</ul>
<li class="item_lvl_1">
<li class="item_lvl_1">
xpath = //ul[#class="menuBar_menu_lvl_0"]//li[#class="item_lvl_1"]//ul[#class="menu_lvl_1"]//li[#class="item_lvl_2"]
This is also giving me item number 3 elements along with item level 2. I want to get each level item correctly and separately. Anybody's help would be highly appreciated
Welcome to SO.
Here is the sample that used.
<html>
<body>
<div>
<ul class="menuBar_menu_lvl_0">
<li class="item_lvl_1">
<li class="item_lvl_1">
<ul class="menu_lvl_1">
<li class="item_lvl_2">Level1-li1</li>
<li class="item_lvl_2">Level1-li2</li>
<li class="item_lvl_2">
<ul class="menu_lvl_2">
<li class="item_lvl_3">Level2-li1</li>
<li class="item_lvl_3">Level2-li2</li>
<li class="item_lvl_3">Level2-li1</li>
</ul>
Level1-li3
</li>
</ul>
<li class="item_lvl_1">
<li class="item_lvl_1">
</ul>
</div>
</body>
</html>
And below is the xpath
//ul[#class='menu_lvl_1']//li[not(parent::ul[#class='menu_lvl_2'])]
Here is the output:
Here is the method to get the text from parent element only.
def get_text_exclude_children(element):
return driver.execute_script(
"""
var parent = arguments[0];
var child = parent.firstChild;
var textValue = "";
while(child) {
if (child.nodeType === Node.TEXT_NODE)
textValue += child.textContent;
child = child.nextSibling;
}
return textValue;""",
element).strip()

accessing translated header in FCE fails

I have a Typo3 Page with several wrappers and referenced elements on it.
I'm using flux-grid to create the content of the wrappers and then access it like this:
<v:variable.set name="contentElements" value="{flux:content.get(area:'content', render:'FALSE')}" />
<ul class="myClass">
<f:for each="{contentElements}" as="contentElement" iteration="iteration">
<li>
<h3 data-number="{iteration.cycle}">{contentElement.header}</h3>
<ul class="content" id="acc_{v:format.sanitizeString(string: '{contentElement.header}')}">
<li>
<v:content.render contentUids="{0:contentElement.uid}" />
</li>
</ul>
</li>
</f:for>
</ul>
Problem is, I always get the default language for contentElement.header instead of the translated version. The content itself that's been fetched via v:vcontent.render is shown in the correct language.
What am I doing wrong?
(Typo3 8.7.9)
I had to get the content first and then render it separately:
<f:for each="{contentElements}" as="contentElement" iteration="iteration">
<v:variable.set name="head" value="{v:content.get(contentUids: '{0: contentElement.uid}', render:'0')}" />
<v:variable.set name="theContent" value="{v:content.get(contentUids: '{0: head.0.records}', render:'0')}" />
<li>
<h3 data-number="{iteration.cycle}">{theContent.0.header}</h3>
<ul class="content" id="acc_{v:format.sanitizeString(string: '{theContent.0.header}')}">
<li>
<f:format.raw>{theContent.0.bodytext}</f:format.raw>
</li>
</ul>
</li>
</f:for>
Hope it helps someone...

Reuse and pass dynamic object (CurrentPage) to Partial View MVC Umbraco

I'm somewhat (6 months) new to MVC, and I like to use as little as code as possible, especially when it comes to reusable code, etc. I'm using Umbraco v7.2, and I have (3) tabs, all which use the same data type (custom grid v7).
The grid has (4) fields. Basically all (3) sections on my page are the same w/ the exception for the header and the object that is called (the dynamic object is what has the properties in them for the tab, which as I stated earlier, are the same).
How can I call a partial view and reuse the same code? The "foreach" is where I need to have this partial view called, as you can see it uses the same exact code w/ the exception of the object being iterated.
The "CurrentPage.XXXX" is what I need to pass, and I can have the same iterator
#foreach(var XXXX in CurrentPage.XXXX) <---- partial view
View:
#inherits Umbraco.Web.Mvc.UmbracoTemplatePage
#{
Layout = "Master.cshtml";
}
<article class="accordion-wrapper">
<div class="accordion-container accordion-contact">
Leadership Team
#foreach (var leadership in CurrentPage.leadershipTeam)
{
<section class="clearfix">
<div class="col-md-6 col-sm-6">
<ul>
<li>#leadership.contactName</li>
<li>#leadership.contactTitle</li>
</ul>
</div>
<aside class="col-md-6 col-sm-6">
<ul>
<li>#leadership.contactPhone</li>
<li>
#leadership.contactEmail
</li>
</ul>
</aside>
</section>
}
</div>
</article>
<article class="accordion-wrapper">
<div class="accordion-container accordion-contact">
The Lenders One Team
#foreach (var lenders in CurrentPage.lendersTeam)
{
<section class="clearfix">
<div class="col-md-6 col-sm-6">
<ul>
<li>#lenders.contactName</li>
<li>#lenders.contactTitle</li>
</ul>
</div>
<aside class="col-md-6 col-sm-6">
<ul>
<li>#lenders.contactPhone</li>
<li>
#lenders.contactEmail
</li>
</ul>
</aside>
</section>
}
</div>
</article>
.... another one here but omitted for brevity
And turn it into:
<article class="accordion-wrapper">
<div class="accordion-container accordion-contact">
Leadership Team
#Html.Partial( ?????? )
</div>
</article>
<article class="accordion-wrapper">
<div class="accordion-container accordion-contact">
The Lenders One Team
#Html.Partial( ?????? )
</div>
</article>
Partial ???
#foreach (var contact in ??????)
{
<section class="clearfix">
<div class="col-md-6 col-sm-6">
<ul>
<li>#contact.contactName</li>
<li>#contact.contactTitle</li>
</ul>
</div>
<aside class="col-md-6 col-sm-6">
<ul>
<li>#contact.contactPhone</li>
<li>
#contact.contactEmail
</li>
</ul>
</aside>
</section>
}
Appreciate it ;)
EDIT:
To clarify, I've used partial views before in Umbraco. The issue above is I have (3) different objects (grids in u7). How the grid works in Umbraco is you create a new data type, and define certain fields in that data type (textbox, media picker, etc). You can then add properties to document types (in this case I used the custom grid I created). Once a page is created, based off a document type, properties are inherited.
For the contact page, I needed (3) separate grids. However each grid has different data in them. Therefore this is (3) different JSON objects, which I iterate over. In the above code, the (3) JSON objects are:
leadershipTeam
lendersTeam
avisoryBoard (the one omitted for
brevity)
How can I pass (CurrentPage.JSONobjectHere) to the partial view, using only ONE partial view for all THREE sections?
Did something similar to this once.
Call your partial like this:
#Html.Partial("YourPartialName", (object)CurrentPage.lendersTeam)
And then use a dynamic as a model in your partial:
#model dynamic
#foreach (var contact in Model)
{
<section class="clearfix">
<div class="col-md-6 col-sm-6">
<ul>
<li>#contact.contactName</li>
<li>#contact.contactTitle</li>
</ul>
</div>
<aside class="col-md-6 col-sm-6">
<ul>
<li>#contact.contactPhone</li>
<li>
#contact.contactEmail
</li>
</ul>
</aside>
</section>
}
This is not too difficult. In the call to the partial, just use the name of the partial. This is the filename of the partial without the extention. The current "Model" will also be available in your partial without you have to pass something to the partial.
<article class="accordion-wrapper">
<div class="accordion-container accordion-contact">
Leadership Team
#Html.Partial("NameOfThePartialWithoutExtention")
</div>
</article>
If you inherit from UmbracoTemplatePage or the UmbracoViewPage, then you can use the model as if you were in the View itself.
#inherits Umbraco.Web.Mvc.UmbracoTemplatePage
#foreach (var contact in CurrentPage.Children)
{
<section class="clearfix">
<div class="col-md-6 col-sm-6">
<ul>
<li>#contact.contactName</li>
<li>#contact.contactTitle</li>
</ul>
</div>
</section>
}
Thanks Morten OC. Thumbs up. I was using NestedContent and calling Partial view to render IPublishedContent, but also wanted access to CurrentPage.
Simple cast to object first worked. To elaborate, here's some extra code in case someone needs the same -
Html.RenderPartial("~/Views/Partials/MyPartial.cshtml",
item, //for me this is an IPublishedContent
new ViewDataDictionary { { "CurrentPage", (object)CurrentPage } });
Then in my Partial, shortened for brevity -
#inherits Umbraco.Web.Mvc.UmbracoViewPage<IPublishedContent>
#{
dynamic CurrentPage = ViewBag.CurrentPage;
}
<p>#CurrentPage.Name</p>
So my Model is IPublishedContent (since I was iterating through nested contents)
And then in ViewBag you'll have a reference to CurrentPage. I named it CurrentPage just so I could continue using CurrentPage as we typically do in Umbraco.
Cheers Morten H5YR

how to get url segment in yii

I am new to YII and i want to get the controller name i hit to add active class in menu item .my URL is like this www.myblog.com/news . I want to get the parameter "news" .Without params are possible in yii like codeigniter $product_id = $this->uri->segment(4);
my menu structure is like this
<ul class="nav navbar-nav">
<li class="active">News / Article</li>
<li>Players</li>
<li>Forum</li>
<li class="dropdown">
Rules <b class="caret"></b>
<ul class="dropdown-menu">
<li>Action</li>
<li>Another action</li>
</ul>
</li>
<li>Profile</li>
<li>Gallery</li>
</ul>
Controller Name -
Yii::app()->controller->id;
Action Name -
Yii::app()->controller->action->id;
Yii::$app->controller->id;
and
Yii::$app->controller->action->id;
Yii::$app->request->pathInfo
then take what you want

Google Rich Snippets & Warning Messages

When using the Google Rich Snippet Tesing Tool, I am getting a warning when the count=0 for the reviews->aggregate reviews snippet. Below is an example of the HTML I am using.
Does Google not validate the review if the count is 0. I checked when a review is added and the page validates fine. If so I am guessing I wont get the additional info shown in the SERP until someone makes a comment.
<div id="placeinfo" class="hreview-aggregate clearing">
<div id="details" class="vcard item">
<h1 class="fn org" id="pagetitle">Showcase Cinema, Coatbridge<span class="hide">, Glasgow</span></h1>
<ul id="rating-review" class="clearing">
<li class="rating-holder clearing"><div class="rating average big-rating bw-0">0</div></li>
<li>Add a review<span class="count"><span class="value-title" title="0"></span></span></li>
</ul>
<ul id="place-contactinfo">
<li class="adr">
<ul class="clearing">
<li class="street-address">
Barrbridge Leisure Centre, Coatbridge</li>
<li class="locality">, Glasgow</li>
<li class="postal-code">, G69 7TZ</li>
</ul>
</li>
<li class="phone tel">0871 220 1000</li>
<li class="url"> www.showcasecinemas.co.uk</li>
<li class="geo">
<span class="latitude"><span class="value-title" title="55.8475380" ></span></span>
<span class="longitude"><span class="value-title" title="-4.0645180"></span></span>
</li>
</ul>
</div>
Per spec of microformats, count should be a positive integer, and rating should be something between 1.0 and 5.0 (rating accepts other ranges, once you define them).
In other words, we (and google) do not expect an aggregate review with 0 votes, 0 reviews and no rating. When it is empty, consider not using this microformat, or consider making at least one review by yourself, this countings and rating will never be 0