#content $key= vs #if in dust - dust.js

I have the following code:
{#data.merchantModel}
<div class="address">
{#content $key="content:combinedAddr" merchantAddress1="{merchantAddress1}" merchantAddress2="{merchantAddress2}"/}
</div>
{:else}
<div class="address">{merchantAddress1}</div>
more code...
{/data.merchantModle}
I'm working with Webcore/NodeApp but everything after the {:else} doesn't get rendered. If I comment it out everything is fine. Not sure why webcore doesn't like the {:else} but was wondering if there's another way to write the above code?
Still trying to wrap my head around dust.

Looks like you need to close your content tag and model is misspelled on the closing tag:
{#data.merchantModel}
<div class="address">
{#content $key="content:combinedAddr" merchantAddress1="{merchantAddress1}" merchantAddress2="{merchantAddress2}"/}
</div>
{:else}
<div class="address">{merchantAddress1}</div>
more code...
{/content}
{/data.merchantModel}

Related

create relative links with Thymeleaf

I have the following code which loops through a list of countries and creates a href links
<div class="container" th:each="country: ${countryList}">
<a th:href="${country.countryAbbr}"><div clss="row" th:text="${country.country}"></div></a>
</div>
The current page url is "localhost:8080/directory", and the generated url is showing as
"localhost:8080/us"
How can I make the url show as "localhost:8080/directory/us"
I want "us" to be added to the current url of the page.
Try create the following code in your Controller class.
#RequestMapping(value="/", method=RequestMethod.GET)
public String rootGet() {
return "redirect:/directory";
}
You can use ServletUriComponentsBuilder:
<div th:with="urlBuilder=${T(org.springframework.web.servlet.support.ServletUriComponentsBuilder)}"
class="container" th:each="country: ${countryList}">
<a th:href="${urlBuilder.fromCurrentRequest().path(${country.countryAbbr}).toUriString()}">
<div clss="row" th:text="${country.country}"></div>
</a>
</div>
Give a try to this one
<div class="container" th:each="country: ${countryList}">
<a th:href="#{${country.countryAbbr}}"><div clss="row" th:text="${country.country}"></div></a>
</div>
Using # usually resolves the default context but I am not aware of your environment.
For example, if you had Tomcat .war file, and your application would be hosted at localhost:8080/myApp, you would want result /myApp/us rather then /us. # would do that trick.
If above is not relevant for you, use this one:
<div class="container" th:each="country: ${countryList}">
<a th:href="#{'/directory/' + ${country.countryAbbr}}"><div clss="row" th:text="${country.country}"></div></a>
</div>

Angular 2 Dart: Template syntax - how to concatenate strings?

Feels like a dumb question but I do not get it. How can I do fast string concatenation in Angular 2 Dart templates?
I have a seperate html file for my component lets say my_component.html:
Works:
....
<div id="abc">
{{order.pickupPlace.email}}
</div>
...
Works:
....
<div id="abc">
{{ ((order.pickupPlace.state) ? order.pickupPlace.state+" ":'')}}
</div>
...
Does not work:
....
<div id="abc">
{{"<br/>"+order.pickupPlace.email}}
</div>
...
Does not work:
....
<div id="abc">
{{order.pickupPlace.name+" "+order.pickupPlace.email}}
</div>
...
Have tried to find an answer in the docs here (https://webdev.dartlang.org/angular/guide/template-syntax#!#expression-operators) but no luck.
Of course I could use *ngIf on every element which I output conditionally but is there a way for simple string concatenation?
The best way is to declare a getter inside your Component controller that does the concatenation for you, you will get dart syntax support and the html template will looks cleaner.
String get myConcatenation => "${order.pickupPlace.name}${order.pickupPlace.email}";
<div id="abc">
{{myConcatenation}}
</div>
The last two examples can be made to work easily:
<div id="abc">
<br/>{{order.pickupPlace.email}}
</div>
And:
<div id="abc">
{{order.pickupPlace.name}} {{order.pickupPlace.email}}
</div>
Angular handles this pretty well. If you need some more complicated logic you can move it to the Dart code (but you cannot use HTML there easily).
If you find creating lot of weird logic consider creating more smaller components that can handle this for you.

MODX Articles: Can't retrieve article image with getResources

I am running MODX Revo 2.3.2 with Articles and getResources. On my start page, I wan't to show the 4 most recent articles by calling getResources. However, it does not show the image. Tried to output it without phpThumbof, but it does not work out at all.
[[getResources?
&parents=`11`
&tpl=`articleRowTpl`
&includeTVs=`1`
&processTVs=`1`
&showHidden=`1`
&limit=`4`
]]
My articleRowTpl looks like this:
<article class="blog-item blog-full-width">
<div class="blog-thumbnail">
<img alt="" src="[[+tv.articleImage:phpthumbof=`w=750&h=200&zc=1`]]">
</div>
<div class="blog-full-width-date">
<p class="day">[[+publishedon:strtotime:date=`%d`]]</p><p class="monthyear">[[+publishedon:strtotime:date=`%b %Y`]]</p>
</div>
<div class="blog-content">
<h4 class="blog-title">[[+pagetitle]]</h4>
<p>[[+introtext:default=`[[+content:ellipsis=`400`]]`]]</p>
Mehr lesen...
</div>
</article>
There are no errors, it just does not output the image path. I double checked the placeholder and the prefix, which defaults to tv. as the documentation says.
Alright, found it. I just removed the TV-Prefix of getResources with
tvPrefix=``
and now I can access the TV with [[+articleImage]].

<br /> inside <div> tag wont work MVC

I've got problem with this line:
<div class="TrescPotwierdzTresc">#Model.Article</div>
The problem is with "br" tag inside #Model.Article wont work. I can see this tag after page load, but text is still in the same line. WHen i do something like this:
<div class="TrescPotwierdzTresc">#Model.Tresc br #Model.Tresc</div>
The br tag between "#Model.Tresc" elements work fine. Do You have any idea why is that happening ?
Try this:
<div class="TrescPotwierdzTresc">#Html.Raw(Model.Article)</div>
Html.Raw returns markup that is not HTML encoded.

<data:post.title> returns title of blog and not post title

Hi I'm trying to convert a static html and css design to a blogger template. I've run into an issue where i expect the post includable to return the post title but instead is returning the blog title. Here is the includable code for the post and below it is the include code that is called in the main includable that houses the html structure. Please any ideas as to how i might resolve this would be very grateful.
<b:includable id='post' var='post'>
<!--Article Summary-->
<b:if cond='data:post.title'>
<h1 class="article-title">
<data:post.title/>
</h1>
<b:else/>
<h1 class="article-title">
<data:post.title/>
</h1>
</b:if>
<p class="posted-by">
by
<em class="author-name"><data:post.author/></em>
on
<span class="date"><data:post.dateHeader/></span>
</p>
<p class="article-content">
<data:post.body/>
</p>
READ MORE
</b:includable>
<b:if cond="data:blog.url == data:blog.homepageUrl">
<div class="article-summary">
<img class="article-image" src="https://lh3.googleusercontent.com/article-main-image.jpg" alt="article-main-image"/>
<b:include name="post"/>
</div>
</b:if>
is correct, so instead I'd be curious about whether or not you're including from the right place. For example, are you in the MOBILE section vs the NON-MOBILE section of the template?

Resources