Need substring capability in dust #206

rragan opened this Issue Dec 14, 2012 · 7 comments


None yet

3 participants


I am getting address in a data model, if the address is greater than 24 characters I need to trim it show "…" after 24 characters else show full address. I was not able to use CSS text-overflow: ellipsis as the data is shown in tag of a select tag.

Is there a way to do a substring operation in dust? This is pretty much a purely presentation need so burdening the model generation logic with it seems wrong.


we have this debate a while back and the best fit for these things are helpers IMO.

We do that here at LI.


In the interest of not diverging too much should we choose to standardize this, what I built is

{@substr str="xxx" begin="x" end="y" len="z" /}
begin is optional, zero if omitted
end and len are choices with len taking priority if the user supplies both.
If len is present, str.substr(begin,len) is used for the result.
if end is present, str.slice(begin,end) is used for the result
if end and len are both missing then you get the whole string back (e.g. str.substr(0).

I provided both end and len params to avoid any need to do math computations if the user has one or the other as @math cannot be used to compute a value for another helper -- using helpers with helpers is a subject we need to think about.


I presume then that substr is not considered of wide enough interest to bundle it in the standard helpers and sites should implement it if they think they need it. Is that right?


we can always create a new repo of formatting helpers:) and open it up for others to use.


A library of shareable partials seems fine to me. Folks could put whatever they want there. I don't know that we need much more than that. Maybe some initial folder structure to provide guidance for categories of partials (e.g. string related, control structures,...)


@rragan @vybs I am going to close this issue, because it was resolved. If we want to discuss about creating a new repo, or folder structure for helpers, we should create a new discussion or a new issue.
In this way we maintain a relationship between the title and the content of the thread.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment