How can I link a hst:sitemenu to a ftl? - freemarker

I am trying to link a menu to his correspondent ftl and I don´t understand which are the proper steps I have to take. I didn´t found any usefull documentation about it. All the help is welcomed.

Basically, you need to retrieve the menu in a component and put that on the request. In the ftl you can then reference the menu. You can use the essentials menu component or the dynamic menu component. Or you have a custom component. I'd suggest starting an archetype project and installing the simple content from essentials. This should add a menu that you can look at to see how it works.
An example from one of our online tutorials looks like this:
<#include "../include/imports.ftl">
<#if menu??>
<div class="hst-container">
<div class="hst-container-item">
<#if menu.siteMenuItems??>
<#list menu.siteMenuItems as item>
<#if item.selected || item.expanded>
<div class="list-group left-nav">
${item.name?html}
<#list item.childMenuItems as item>
<i class="fa fa-angle-right"> </i>${item.name?html}
</#list>
</div>
</#if>
</#list>
</#if>
</div>
</div>
</#if>

Related

JBake: list all posts with a particular tag (tagged_posts)

In freemarker, how do I iterate over all blog posts with a particular tag, for example the tag "algorithms"?
<#assign relatedBlogs = ...>
<#if relatedBlogs?size > 0>
<h2>Related blog posts</h2>
<ul>
<#list relatedBlogs as blog>
<li>
${blog.title}
</li>
</#list>
</ul>
</#if>
This doesn't work for me:
<#assign relatedBlogs = tagged_posts["algorithms"]>
This doesn't work either:
<#assign relatedBlogs = tags["algorithms"].tagged_posts>
tags is a sequence, and to use tags[...] you need a hash.
I ended up getting it to work through ?filter()and ?first:
<#assign relatedTags = tags?filter(tag -> tag.name == "algorithms")>
<#if relatedTags?size > 0>
<#assign relatedTag = relatedTags?first>
<h2>Algorithms related blog posts</h2>
<ul>
<#list relatedTag.tagged_posts as blog>
<li>
${blog.title}
</li>
</#list>
</ul>
</#if>
This won't scale well, because filter() iterates the tags for every page, but it works fast enough for websites with hundreds of pages. Here's the related issue.

Click on a element with specific text

Alright, I have a item which has this class class="country" and there are 12 elements with the same class. Now I want to get a element on its value. For example Italy. And now I want to click on a link in this item. The class of the link is class="link". So basically I want to click the link of the item with the name Italy
My code at the moment:
cy.get('.country').should('have.text', 'Italy').click();
HTML
<div class="countries">
<div class="text">
<h3></h3>
<div class="country">Italy</div>
<h4>Yala</h4>
<p>test</p>
<a class="link" href="/mysite">Show details</a>
</div>
</div>
Should() is an assertion and won't select the element you want.
you probably want the contains() function.
cy.get('.country').contains('Italy').click()
Best

How to print Freemarker list options in two separate columns while looping

I would like in Freemaker that my value is listed in 2 columns.
My code so far :
<#list orderItem.options as option>
<tr>
<td style="font-family: Arial,Helvetica,sans-serif;font-size: 16px;">
<div class="row">
<#if option.fileUrls??>
<span>
<span>${option.name}:
</span>
<#fileLinks option.fileUrls = "option.fileUrls"/>
</span>
<#else>
<#if option.value != 'Geen'>
<div class="column">${option.name}: ${option.value}</div>
${option.name}: ${option.value}
- -
</#if>
</#if>
</div>
</td>
</tr>
</#list>
So I want :
I have a webshop where people can buy food.
Food can have multiple options : Size, Salt, Saus
I want that my products will be printed in my mail this way :
Product name : Product name:
Size: small Size: Big
Salt : Yes Salt: no
Saus: Mayonaise Saus: Cocktail
You really should be limiting the scope of your question's example. I am not sure what the extra markup should do, or where it should be placed. But is it something like this you are looking for?
<table>
<#list orderItem.options as option>
<#if option.fileUrls??>
<tr>
<td>
<span>${option.name}</span>
<span><#fileLinks option.fileUrls/></span>
</td>
<td>
<#if option.value != 'Geen'>
<span>${option.value}</span>
</#if>
</td>
</tr>
</#if>
</#list>
</table>
I am sorry if this is not exactly what you are looking for, but your example is confusing. At least you might take my example response and go from there.
I have couple questions if you don't mind:
Is Product name also part of the options stored in orderItem.options ?
Is having file link exclusive to a certain option ?
Please edit your question and post the Java model (class) OrderItem
I got what you want, need to know your design approach to provide the best solution that suites your design.

How to get simple freemarker if statement match some string

I have the following freemarker code
<#assign carsPriceDescriptionSB = "Price guide" >
<#if vehicle.getPriceDescription == carsPriceDescriptionSB >
<div class="cgl304 data-source small">Some text
<br/><br/>
</div>
</#if>
What I want to do is check that the value of vehicle.getPriceDescription() is equal to Price guide and if the result is true display the block of code
To access the get method you should drop the 'get' or explicitly specify the method name followed by brackets. Avoid using the second method unless necessary.
Normally omit the get prefix
<#assign carsPriceDescriptionSB = "Price guide" >
<#if vehicle.priceDescription == carsPriceDescriptionSB >
<div class="cgl304 data-source small">Some text
<br/><br/>
</div>
</#if>
Or if it is not a get method then specify the entire method name
<#assign carsPriceDescriptionSB = "Price guide" >
<#if vehicle.readPriceDescription() == carsPriceDescriptionSB >
<div class="cgl304 data-source small">Some text
<br/><br/>
</div>
</#if>

KendoMobile UI template with query strings

UPDATE -
<script id="clientEvals-template" type="text/x-kendo-template">
<ul data-role="listview" data-style="inset">
<li>
${entry_stamp}
</li>
</ul>
</script>
It seems that chars like the ? and the = contained in a kendomobile template break the local link
ie this WONT work:
<ul data-role="list-view">
<li>${entry_stamp}</li>
</ul>
</script>
But this WILL work (without the query string
<script id="clientEvals-template" type="text/x-kendo-template">
<ul data-role="list-view">
<li>${entry_stamp}</li>
</ul>
</script>
Ive tried escaping this with mutiple chars ie \ \ // etc.. with now luck
Anyone know how to format this so that the local view is found WITH the query string?
This was a known issue, it was resolved in the current service pack release.
the fix is to format all ampersands using html encoding inline, in any icenium template script areas
ie.
<!-- always use inline html encoding in icenium template scripts ie. & -->
<script id="clientEvals-template" type="text/x-kendo-template">
<ul data-role="listview" data-style="inset">
<li>
${entry_stamp}
</li>
</ul>
</script>

Resources