0

Sorry bad title. I'm absolutely stumped on how to do this. I'm using dust for my templating (which works fine) but dust doesn't accept colons (:) as key names. So I'm trying to somehow still grab a key with a colon (user:description) and insert it into when I'm looping through my dust template. However the code below puts all the values into each individual div (see below). How would I make this work so that it enters the "user:description" value once per loop (or div creation)? I've been banging my head for hours. Any help is appreciated

var compiled = dust.compile($('.media-gallery').html(), "blocks");
var items = [];
dust.loadSource(compiled);

        $.getJSON("services/mediaType.json", function(data) {
            $.each( data.results, function( key, val ) {
                items.push("<div class='" + key + "'>" + val['user:description'] + "</div>");     
                dust.render("blocks", val, function(err, out) {
                    $('.media-filter').append(out);
                });                                        
            });
        $(".resource-description").append(items.join(""));
        });

HTML with Dust

<div class="media-gallery">        
    <h6>{pageTitle}</h6>
    <p class="content-type">{mediaType}</p>      
    <p class="resource-description"></p>
</div>   

TYPICAL OUTPUT

<div class="media-gallery">        
    <h6>Dog Images</h6>
    <p class="content-type">image</p>      
    <p class="resource-description">
        <div class="0">cats description</div>
        <div class="1">mouse description</div>
        <div class="2">dog description</div>
    </p>
</div> 

1 Answer 1

1

You are out of luck unless you either write a custom helper or change the model to not contain :'s. There is an open issue on this problem. https://github.com/linkedin/dustjs/issues/229

Sign up to request clarification or add additional context in comments.

1 Comment

Bummer thanks for the reply @rragan. Can you do this with a dust helper though? I've looked through the documentation and haven't found something that does this unless I'm just overlooking something.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.