How to get the total items in an array(array length) in dust.js - dust.js

I can't seem to figure out(I'm pretty sure that I'm over thinking or not thinking here) a way to get the length of an array in the following example. Can anyone please help me, or direct me to a good tutorial. https://github.com/linkedin/dustjs/wiki/Dust-Tutorial has mentioned the {#size} helper but does not have any examples.
<ul total-tems={#items.length/}>
{#items}
<li class="item-{$idx}">{.title}</li>
{/items}
</ul>
Thank you in advance.

Yep, I was clearly overlooking. I was not including ( require('dustjs-helpers'); ) in order to use
<ul total-tems="{#size key=items /}">
Hope this will help others out as well.

I don't know if is it a new feature of dustjs but now you can simply use {items.length} to access the array length with no need of helpers.

Related

Umbraco, adding attachments to articles in back-end and then showing them in front-end CMS

On my Umbraco website, I have the section which shows latest News. Each news is one article.
Unfortunately, I can't add any attachments to any News article in back-end so users could see that attachment(s) on front-end of website and download them if they want to. This is how I it should look like
https://imagizer.imageshack.us/v2/895x383q90/826/cozp.jpg
Is this possible to do? While I was using Joomla CMS it was very easy by installing additional module/component which took me only 15 minutes to set.
Any help is appreciated and many thanks in advance for prompt replies!
MC2012
The solution is fairly simple:
Add the attachments to a folder in the 'Media' section
Add a field to the document type that the page uses called 'attachments' and use the datatype 'Multi-node Picker'
On the page content pick the attachments you are interested in
Render the list of attachments (http://our.umbraco.org/projects/backoffice-extensions/ucomponents/questionssuggestions/26638-Multi-Node-Tree-Picker-help-with-example-code-(in-Razor))
using something like:
<article>
#if(Model.HasValue("attachments")){
<ul>
#foreach(var item in Model.attachments){
var node = Library.NodeById(item.InnerText);
<li>
#node.Name
</li>
}
</ul>
}
</article>
Thank you very much for fast answer. However, in the meantime I have find solution. Here is the link
http://our.umbraco.org/forum/using/ui-questions/47616-Adding-attachments-to-articles-in-back-end-and-then-showing-them-in-front-end-CMS
I hope someone else will have some use of it because it is great solution.
BR,
MC2012

multiple Html.Attr on one tag in razor?

how do i use multiple Html.Attr on one tag as follows in a razor view? this doesnt work.
<tr #Html.Attr("style", "color: #FF3D0D;")
#Html.Atrr("data-item", Model.ItemNumber)>
I'm not familiar with the .Attr helper either, but just incase you copied the code directly from your view, there is a typo, you have #Html.Atrr which I'm guessing should be #Html.Attr for data-item
So, it has come to this..
#Html.Atrr("data-item", Model.ItemNumber)
- VS -
data-item="#Model.ItemNumber"
Just one word: don't. Your markup AND every single human being on earth will benefit from the later much straight forward syntax. The HtmlHelper Html.Atrr doesn't help at all, no value.
Also, the following works for me:
<body #Html.Raw("data-test1=\"1\"") #Html.Raw("date-test2=\"2\"")>
.. and renders:
<body data-test1="1" date-test2="2">
You probably should be using #Html.Attr and not #Html.Atrr... or, as others have pointed out, just writing the attributes explicitly.

Customized error handling

How can I achieve that the code below only will be executed if there is an HTML input-Tag? So that it won't be executed by the HTML label-Tag.
<div class=\"field_with_errors\">#{html_tag}</div>".html_safe
Thanks in advance!
Regards
Silvan
I'm not 100% sure what you're asking, but if you're asking what I think you are you could do something like:
<div class=\"field_with_errors\">#{html_tag}</div>".html_safe unless html_tag.nil?
If this isn't what you're looking for, could you please explain more about what you want to achieve?

Can I use this code directly in a ASP.NET MVC 3 Razor View instead of declaring variables?

I have values in a resx file that I would like to output in my razor view. When I try it this way, it blows up.
<li>
#ResourceFacade<Global>.GetString("MenuLabelSupport");
</li>
but if I do this, it works as expected.
#{
var menuLabelSupport = ResourceFacade<Global>.GetString("MenuLabelSupport");
}
<li>
#menuLabelSupport
</li>
I would really like to use the first implementation. Perhaps my syntax isn't quite right? If anyone sees, that I'm doing something incorrectly, please let me know. Thank you so much for any tips or advice.
Try like this:
#(ResourceFacade<Global>.GetString("MenuLabelSupport"))

Textile question: redcloth anchor links

How do I write this in textile (i'm using the redcloth gem)
Visit the Useful Tips Section
<a name="tips">Useful Tips Section</a>
I know the first part, "Visit the Useful Tips Section":#tips but how do I make the named anchor?
Thanks!
Deb
The textile manual seems to indicate that there's no way to do so other than just using straight HTML:
<a name="tips"></a>
<h1>Useful Tips Section</h1>
The answer that suggests:
h1(#tips). Useful Tips Section
is incorrect as it will generate:
<h1 id="tips">Useful Tips Section</h1>
which is not a named anchor. However, you could use some Javascript to make this work.
h1(#tips) Useful Tips Section. -- Achieves the same effect (with some css)

Resources