Looking for a way to load 1 of 5 sections of a partial - dust.js

I'm trying to find a way to load 1 section of a partial that would have 5 sections in all.
The idea behind it is to load either the US, UK, DE, FR or DU section of a partial depending the countryCode. CountryCode gets loading into {sys.pageInfo.countryCode}
I've been able to find an #if condition but this only works if I want to load 1 of 2 sections
{#if cond="'{countryCode}' == 'US'"}
<p>is country code US</p>
{:else}
<p>is NOT country code US</p>
{/if}
or
{#eq key=countryCode value="US"}
<p>is country code US</p>
{:else}
<p>is NOT country code US</p>
{/eq}
#eq was working but doesn't seem to be working for me atm.
Again the above works well to load 1 or 2 sections but I need a way to load 1 of 5 sections. Is there a way of doing this?
Thanks,
Tom

You can use {#select}.
{#select key="{countryCode}"}
{#eq value="US"}Hi{/eq}
{#eq value="UK"}Hello{/eq}
{#eq value="FR"}Bonjour{/eq}
{#default}Hello{/default}
{/select}

Related

TemplateRenderer returning null (Vaadin Flow / 14.1)

For one of the columns in my Grid i use a TemplateRenderer (an icon is shown to give a hint about a possible issue with this row):
grid.addColumn(TemplateRenderer.<T>of("<iron-icon icon='[[item.icon.name]]' title='[[item.icon.tooltip]]' style='width: 1em;'></iron-icon>")
.withProperty("icon", item -> StatusHint.of(item))
...
;
For some items, this template is not relevant (there are no issues), so property "icon" is null. The result is this HTML: <iron-icon style="width: 1em;" title="undefined"></iron-icon>.
Also note that the 'icon' attribute is not shown and the title attribute is undefined?!
Although the browser does not show anything, the clueless HTML code is ugly imho (do not know if there are also performance penalties).
An empty cell or <div></div> looks much better.
How do i accomplish this? The API does not give me any hints.
It's a bit elaborate, but you can use Polymer's dom-if templates to create conditional subtemplates for cases where you can't just bind a property. Here's an example that prints "even" or "odd" depending on whether a Person's age is even or odd:
grid.addColumn(
TemplateRenderer.<Person>of(
"<template is='dom-if' if='[[item.even]]'><b>even</b></template><template is='dom-if' if='[[!item.even]]'><i>odd</i></template>"
).withProperty("even", p -> {
int age = p.getAge();
return age % 2 == 0;
}))
.setHeader("Is age even or odd?");

Umbraco Macros Appear to be Rendering Two or More Times

Upon debugging my Umbraco solution (which was given to me by an outside consulting firm) and checking my error logs, I have noticed that it would appear that my macros are being hit in the code anywhere between 2 and 5 times. The macro isn't rendered that many times, it is just logging a warning and stepping through the code that many times.
Why is this? Is this basic Umbraco functionality or is there a mistake in my code?
My view under the Views -> MacroPartials folder looks like this:
#inherits Umbraco.Web.Macros.PartialViewMacroPage
#if (!string.IsNullOrEmpty(Model.MacroParameters["title"].ToString()))
{
<h2 class="#(Model.MacroParameters["hideBorder"].ToString() == "1" ? "" : "heading-border")">#Html.Raw(Model.MacroParameters["title"])</h2>
}
#if (!string.IsNullOrEmpty(Model.MacroParameters["subTitle"].ToString()))
{
<h2 class="large-body-copy">#Html.Raw(Model.MacroParameters["subTitle"])</h2>
}
Here is how I have the macro set up in the back office:

How can I make a conditional statement like "include?" method in Ruby on Angular ng-if

Sorry about the difficulty for me to make the title much clearer. I'll explain as much as I can.
I use Rails as the backend (API), and AngularJS as the frontend.
I got several article_ids that have been liked(thumb up) from articleCtrl, named $scope.article_has_liked (it's an array contains several article_ids, like [24,45,55] ), just like below, :
articleCtrl.js.coffee
$http.get(url).success((data)->
console.log(data)
$scope.articles = data.articles
$scope.topic = data.topic
$scope.article_has_liked = data.article_has_liked
)
And I pass these article_ids ($scope.article_has_liked) to the show.html, in order to use "ng-if" to conduct a judgement, just like below:
Show.html
<div ng-if="article_has_liked.include?(article.id)">
<button class="btn btn-link" ng-click="likeItOrNot(article.id, topic.id)">
<span class="glyphicon glyphicon-star"></span>
</button>
</div>
<div ng-if="article_has_liked.exclude?(article.id)">
<button class="btn btn-link" ng-click="likeItOrNot(article.id, topic.id)">
<span class="glyphicon glyphicon-star-empty"></span>
</button>
</div>
Here comes the problem !
I'd like to use .include? method in Ruby to determine if the article.id is included by the article_ids that have been liked. If it is liked, I'll give it a solid star. But I found that the Angular seems not to accept the usage, and it returned the error just like below:
Error: Syntax Error: Token 'undefined' expected : at column NaN of the expression [article_has_liked.include?(article.id)] starting at [article_has_liked.include?(article.id)].
throwError#http://localhost:3000/assets/angular.self-cdfe10db265380c82ec938d307fce2720dc9fb9d8cfa21c78928031af124e282.js?body=1:6672:1
ternary#http://localhost:3000/assets/angular.self-cdfe10db265380c82ec938d307fce2720dc9fb9d8cfa21c78928031af124e282.js?body=1:6827:9
_assignment#http://localhost:3000/assets/angular.self-cdfe10db265380c82ec938d307fce2720dc9fb9d8cfa21c78928031af124e282.js?body=1:6800:16
expression#http://localhost:3000/assets/angular.self-cdfe10db265380c82ec938d307fce2720dc9fb9d8cfa21c78928031af124e282.js?body=1:6796:12
_filterChain#http://localhost:3000/assets/angular.self-cdfe10db265380c82ec938d307fce2720dc9fb9d8cfa21c78928031af124e282.js?body=1:6762:16
statements#http://localhost:3000/assets/angular.self-cdfe10db265380c82ec938d307fce2720dc9fb9d8cfa21c78928031af124e282.js?body=1:6742:25
parser#http://localhost:3000/assets/angular.self-cdfe10db265380c82ec938d307fce2720dc9fb9d8cfa21c78928031af124e282.js?body=1:6661:13
$ParseProvider/this.$get</<#http://localhost:3000/assets/angular.self-cdfe10db265380c82ec938d307fce2720dc9fb9d8cfa21c78928031af124e282.js?body=1:7282:1
compileToFn#http://localhost:3000/assets/angular.self-cdfe10db265380c82ec938d307fce2720dc9fb9d8cfa21c78928031af124e282.js?body=1:9215:16
$RootScopeProvider/this.$get</Scope.prototype.$watch#http://localhost:3000/assets/angular.self-cdfe10db265380c82ec938d307fce2720dc9fb9d8cfa21c78928031af124e282.js?body=1:8547:19
ngIfDirective</<.compile/<#http://localhost:3000/assets/angular.self-cdfe10db265380c82ec938d307fce2720dc9fb9d8cfa21c78928031af124e282.js?body=1:14677:9
nodeLinkFn#http://localhost:3000/assets/angular.self-cdfe10db265380c82ec938d307fce2720dc9fb9d8cfa21c78928031af124e282.js?body=1:4960:13
compositeLinkFn#http://localhost:3000/assets/angular.self-cdfe10db265380c82ec938d307fce2720dc9fb9d8cfa21c78928031af124e282.js?body=1:4539:15
compositeLinkFn#http://localhost:3000/assets/angular.self-cdfe10db265380c82ec938d307fce2720dc9fb9d8cfa21c78928031af124e282.js?body=1:4554:13
compositeLinkFn#http://localhost:3000/assets/angular.self-cdfe10db265380c82ec938d307fce2720dc9fb9d8cfa21c78928031af124e282.js?body=1:4554:13
compositeLinkFn#http://localhost:3000/assets/angular.self-cdfe10db265380c82ec938d307fce2720dc9fb9d8cfa21c78928031af124e282.js?body=1:4554:13
compositeLinkFn#http://localhost:3000/assets/angular.self-cdfe10db265380c82ec938d307fce2720dc9fb9d8cfa21c78928031af124e282.js?body=1:4554:13
compositeLinkFn#http://localhost:3000/assets/angular.self-cdfe10db265380c82ec938d307fce2720dc9fb9d8cfa21c78928031af124e282.js?body=1:4554:13
publicLinkFn#http://localhost:3000/assets/angular.self-cdfe10db265380c82ec938d307fce2720dc9fb9d8cfa21c78928031af124e282.js?body=1:4456:30
ngRepeatAction#http://localhost:3000/assets/angular.self-cdfe10db265380c82ec938d307fce2720dc9fb9d8cfa21c78928031af124e282.js?body=1:15463:15
$watchCollectionAction#http://localhost:3000/assets/angular.self-cdfe10db265380c82ec938d307fce2720dc9fb9d8cfa21c78928031af124e282.js?body=1:8718:11
$RootScopeProvider/this.$get</Scope.prototype.$digest#http://localhost:3000/assets/angular.self-cdfe10db265380c82ec938d307fce2720dc9fb9d8cfa21c78928031af124e282.js?body=1:8812:21
$RootScopeProvider/this.$get</Scope.prototype.$apply#http://localhost:3000/assets/angular.self-cdfe10db265380c82ec938d307fce2720dc9fb9d8cfa21c78928031af124e282.js?body=1:9013:13
done#http://localhost:3000/assets/angular.self-cdfe10db265380c82ec938d307fce2720dc9fb9d8cfa21c78928031af124e282.js?body=1:10266:34
completeRequest#http://localhost:3000/assets/angular.self-cdfe10db265380c82ec938d307fce2720dc9fb9d8cfa21c78928031af124e282.js?body=1:10450:7
createHttpBackend/</xhr.onreadystatechange#http://localhost:3000/assets/angular.self-cdfe10db265380c82ec938d307fce2720dc9fb9d8cfa21c78928031af124e282.js?body=1:10405:1
<!-- ngIf: article_has_liked.include?(article.id) -->
So I want to ask if there is any conditional statement which has similar meaning to .include? that I can use in AngularJS "ng-if", or there is any better way for me to conduct this judgement?
Thanks everyone for helping me this confusing question!
That is a JavaScript relating question, not AngularJS. But may that answer your question:
Often you will need to check whether an array contains a certain item. You can do this by using the indexOf() method. If the code does not find the item in the list, it returns a -1.
var article_has_liked = [24,45,55];
if(article_has_liked.indexOf(99) == -1){
alert("data not found");
}
Not sure but you can try something:
<div ng-if="article_has_liked.indexOf(article.id) != -1">
Note: This above condition is to check for include. If it include your article.id in article_has_liked then only execute that block. If you want to check exclude then you can simply use == instead != I hope it works for you.
ng-if="article_has_liked.include?(article.id)"
update to this one:
ng-if="article_has_liked.include?(article.id):false value here"

How do I get a teaser excerpt from a web article / user-posted link?

I have a site where users can submit content based on a link. Is there a way to detect the main content of the link and take a teaser? For example, on Digg, all of the entries have a small clip / excerpt from the link. That's pretty much exactly what I want.
I'm working with Ruby on Rails. I found this question on extracting article excerpts but any tips in the right direction would be helpful.
I found out that Digg uses the Open Graph Protocol (http://ogp.me/) by Facebook.
Ultimately, this was exactly what I was looking for!
The Ruby Gem OpenGraph:
https://github.com/intridea/opengraph
By accessing the metadata tag "description", I got the description e.g.
article = OpenGraph.fetch('http://www.page.com/article/1124')
article.description# => 'This is a small description of the movie'
Some pages (but not most articles) don't have the description.
How to Extract a Webpage’s Main Article Content
Try extracting the text using DOM, here is an example page
<body>
<div>
<ul>
<li>Home</li>
<li>Politics</li>
<li>Health</li>
<li>Travel</li>
<li>About</li>
</ul>
<div>
<div>
<div>
<p><b>MIAMI, Florida (CNN) </b> -- Hurricane Ike weakened slightly...
<p>Ike hit Turks and Caicos Islands Sunday morning, leaving a trail of...
<p>"It pretty much looks like an episode of 'The Twilight Zone,' " said...
<p>Aftwood estimates at least 90 percent of homes he saw on the island were...
<p>The possibility of similar devastation prompted state and local officials...
<p > "Let's hope it's all a false alarm," Louisiana Gov. Bobby Jindal said...
</div>
<div>
<p>Some side-story that we don't really care about.</p>
<p>Another paragraph for this story.</p>
</div>
<div>
<p>Yet another semi-related side-story that we still don't care about.</p>
<p>Another paragraph for this story.</p>
<p>Another paragraph for this story.</p>
<p>Yet another paragraph for this story.</p>
</div>
</div>
<div>© 2008 Cable News Network.<div>
</body>
Clearly, we don’t care about the navigation link text, or the two side-stories. Let’s break it down based on DOM location. We have six tags in the first tag of the second tag of the body. We’ll represent this location as a list of indexes, like (2,1,*). If we group all the text nodes in this fashion, and track how much text each group contains, we get a table like:
location = characters
(1,1,1,1) = 4
(1,1,2,1) = 8
(1,1,3,1) = 6
(1,1,4,1) = 6
(1,1,5,1) = 5
(2,1,*) = 500
(2,2,*) = 100
(2,3,*) = 250
(3) = 26

How to change the look of displaying items of the <struts: checkboxlist >

In the Struts2 application in the jsp page I have a feild where the user can select what ever option he want , i used struts:checkboxlist like this
<s:checkboxlist name="cust.communityList" label="Are You Inteterested In"
list="{'WebSpere Consultuing','Portal Consulting','SOA/BPM Consulting','Content Management',
'DataPower Consulting','Information Management Services','Application Monitoring','Application Security',
'Migration to WebSphere','Application Testing','WebSphere Version Upgrade','JAM/Panther Consulting','IBM Software Procurement','XMLink/Progressions','Other'}" />
It is working fine . But in the browser it's look is not good , It dispalying the list elements in a row wise one after the other ,then in the next row ....
I wanted to display them ,2 in the first row ,next 2 items in the second row ans so on ...
How can i display the checkboxlist items in that way ?
Ok, I just did this via the custom template method. It seemed to get the job done. Look at the docs to see how to pull the original checkboxlist FreeMarker css code into your own project. In summary, pull struts2.core.jar/template/simple/checkboxlist.ftl into your own webapp/template directory and modify it. I make the following changes:
1: at the top of the file, where the iterator tag is, I added the following lines (not the iteratorline) before and after:
<table><tr><td> </td><td> </td><td> </td></tr>
<#s.iterator value="parameters.list">
<#if itemCount % 3 = 0 >
<tr>
</#if>
<td>
2: At the end of the file, where the iterator ends, I added:
<#if itemCount % 3 = 0 >
</tr>
</#if>
</#s.iterator>
</table>
3: That's it. Really, the tutorial tells you what you need to know, it's just a matter of hacking up the FreeMarker code.
You can change the theme for the checkbox OR you can extend the theme and then change it.
Look in your /template/simple/checkboxlist.ftl for the base checkboxlist template.
For info on overriding templates see: http://struts.apache.org/2.0.11/docs/template-loading.html

Resources