meteor - Mixing handlebars.js and CSS - Random background image? -
i set randomly generated background image.
i using meteor , calling flickr api provide random image url set background image.
from i've read, seems css recommended way set background image. there way inject dynamically generated url css? can't seem find examples showing mixing of handlebars.js , css - possible? or should avoiding css , setting background image using traditional html way?
i've been trying 2 different strategies:
1) create css attribute in html url injected via handlebars - can't seem concatenate css attribute handlebars.
2) other method i've tried create css attribute variable in template code, , return html via handlebars, so:
template.backgroundimage.background = function(){ //runs function generate url , add session object flickrrandomphotofromset(setid); //create variable html , css attribute concatenated url var backgroundimage = '<div style="background-image: url('+session.get("randomurl")+')"></div>'; //return resultant variable html via template return backgroundimage; };
then in html have inserted following:
<template name="backgroundimage"> {{background}} </template>
this approach ended working me:
i'm using internal stylesheet define template. url updated match randomly generated url:
<template name="backgroundimage"> <style> body { background-image:url({{background}}); background-repeat: no-repeat; background-position: right top; } </style>
Comments
Post a Comment