translating ejs injection to .dot engine way

44 Views Asked by At

Hey guy i'm having trouble to get this work, any help would be much apreciated

I usually use this in my ejs engine template

<%= blog.created_at.getFullYear() %>
<%= blog.short_name.replace(new RegExp(" ", "g"), "-") %>
<%= blog.content.match(/<img[^>]+src="([^">]+)/)[1] %>

but I have trouble making this work in .dot engine. I know my problem are javascript function, regex and match I'm using. meaning bold part, is not correct here ( getFullYear() , replace(new RegExp(" ", "g"), "-") , match(/]+src="([^">]+)/)[1] )

{%= blog.created_at.getFullYear() %}
{%= blog.short_name.replace(new RegExp(" ", "g"), "-") %}
{%= blog.content.match(/<img[^>]+src="([^">]+)/)[1] %}

what should be use instead in those cases?

Thanks

1

There are 1 best solutions below

0
MikZuit On

after some test I realized:

first : I'm doing this wrong. I'm trying to gen and img's src from a html string (that's what the regex does ) but does it really need to be that way?? ...of course NO. So the best thing in my case is do this on the route before render using underscore.

  _.map(array, function(object,key){
       return _.extend(object, {image: img_sources || 'image'}); 
    });

second: the problem here resides in chars like "(double quotes), [ ] (squarebrackes) , and probably some other . I'have achieved a way to replace all those chars and still the regex work. Use the better the solution above.