Coder Social home page Coder Social logo

slashes url encoded about jsrender HOT 10 CLOSED

borismoore avatar borismoore commented on June 13, 2024
slashes url encoded

from jsrender.

Comments (10)

mesetar avatar mesetar commented on June 13, 2024

this happens on other occasions too!

<a href="/classifieds/favorite.html?id=${id}" class="favstar tipsyn" rel="${id}" title="Dodaj med priljubljene"></a>

outputs

<a title="Dodaj med priljubljene" rel="518" class="favstar tipsyn" href="/classifieds/favorite.html?id=$%7Bid%7D"></a>

from jsrender.

BorisMoore avatar BorisMoore commented on June 13, 2024

${foo} should HTML encode, but not URL encode.
Use {{html foo}} if you don't want any encoding. If you want it to url encode you should write your own URL encoding function, and use {{html myNamespace.myUrlEncode(foo)}}.

That said, I don't know what you are doing to end up with encoding of {{if as %7B%7Bif. It looks like you are encoding your template before using it.

from jsrender.

mesetar avatar mesetar commented on June 13, 2024

but in my case the {{ doesn't get processed.... maybe cause I am fetching the html from json response

from jsrender.

BorisMoore avatar BorisMoore commented on June 13, 2024

Yes, you should check the correctness of the template, and ensure it did not get encoded by your 'ajax pipeline'.

from jsrender.

mesetar avatar mesetar commented on June 13, 2024

strange thing is, that it is working well with jquery's (yours) tmpl...
if I replace

tpl = $(tpl).render(AD);

with

tpl = $.tmpl(tpl, AD).html();

works perfectly

the problem is...that is 2/3 slower! instead of ~70ms i get ~170ms

from jsrender.

mesetar avatar mesetar commented on June 13, 2024

lol, thees git buttons... confusing at times [:D]

now:

I checked the HTML string I get from ajax response and it is OK...I even tried unescape it...

here is my tpl string

<span> <li id="c_${id}" class="tiles ${sponsored} ${region} ${area_id} ${mine}"> <div class="ad_wrapper"> <div class="mine corner_sticker"></div> <div class="chk_classified_box ccol"> <input class="optmenu_chk" type="checkbox" name="chk_classified" value="${id}" /> <a href="/classifieds/favorite.html?id=${id}" class="favstar tipsyn" rel="${id}" title="Dodaj med priljubljene"></a> {{if mine !== ''}}<a href="/oglas/${slug}.html?edit=true" class="edit_ad tipsyn" rel="${id}" title="Popravi oglas"></a>{{/if}} </div> <div class="photo_box ccol"><a href="/oglas/${slug}.html" title="${title}" rel="${slug}" class="appad"><img src="{{if photo}}html ${photo}{{else}}/media/no_photo.png{{/if}}" class="photo" alt="${slashes_title}" /></a></div> <div class="data ccol"> <p class="carea">${area}</p><span class="small when" title="Oddano: ${created}">${tpl_days_ago()}</span> <h3><a href="/oglas/${slug}.html" class="title appad" title="${title}" rel="${slug}">${title}</a></h3> <p><span class="summary gray">${summary}</span></p> <div class="usr_data"> <a href="/oglasi/uporabnik/${OWNER.id}.html" class="tipsyn appclassifieds" title="Prikaži vse oglase uporabnika" >${OWNER.name}</a><br /> <span class="small">${OWNER.address} - ${OWNER.postal} ${OWNER.city} <small class="distance">(<a title="Zračna razdalja" class="set_location distance tipsyn">${tpl_distance()}</a>)</small></span> </div> <span class="cviews"><i>Število prikazov: </i><b class="tipdata">${views}</b></span> </div> <dl class="ccol"> <dt>Področje</dt><dd>${area}</dd> <dt>Prodajalec</dt><dd>${OWNER.name}</dd> <dt>Lokacija</dt><dd><span title="<small>Zračna razdalja:</small> <b class='distance'>${tpl_distance()}</b>" class="tipsyn">${OWNER.city}</span></dd> <dt>Cena</dt><dd><b>${f_price}</b></b></dd> </dl> <div class="price_box ccol"><h4>${f_price}</h4></div> <div class="clear"></div> </div> </li> </span>

from jsrender.

BorisMoore avatar BorisMoore commented on June 13, 2024

I don't understand why you are doing tpl = $.tmpl(tpl, AD).html(); or tpl = $(tpl).render(AD); There is not enough context in this issue to know how you are using templates, and where your problem is coming from.

So I will close this issue. JsRender does not encode { or }. If you sure that you are seeing a bug in JsRender and not in your app, you would need first to create a very simple test case in JsFiddle, showing how JsRender incorrectly encodes url slashes; - showing that the encoding error is happening within JsRender.

from jsrender.

mesetar avatar mesetar commented on June 13, 2024

you might be right that the problem is on my part... but how is that (in my case) tmpl is working OK and render is not?

I tried to make a testcase that behaves the same way as my app, but it works on js fiddle

http://jsfiddle.net/cKW4U/11/

and just to give you context more accuarate version

http://jsfiddle.net/R4k9u/

from jsrender.

BorisMoore avatar BorisMoore commented on June 13, 2024

a) don't load jquery.render.js and jquery.tmpl.js on the same page. They are not designed to be used together in a page. For a given page, choose one or the other.

b) To load a template from a string, first compile as a named template, then render the compiled template using $.render( template, data ), not $( template ).render( data ) - which is designed for the case where the template is declared in a script block, rather than coming from a string:

$.template( "myTemplate", templateString )
var rendered = $.render( "myTemplate", myData );

See the docs here: http://api.jquery.com/category/plugins/templates/ - in particular
http://api.jquery.com/jquery.tmpl/
http://api.jquery.com/jquery.template

JsRender uses the same design except tmpl() is renamed to render().

from jsrender.

mesetar avatar mesetar commented on June 13, 2024

Great! thank you! You are the man!

precompiling did herlp a lot! instead of 70ms I get now <20ms! Plus the photos work too ;)

Thanks again!

from jsrender.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.