TechQA.

RIVETS.JS - What's the correct syntax in order to resolve a placeholder in html image src?

2.3k views Asked by Cisco At 2014-01-02T12:33:58+00:00 02 January 2014 at 12:33 2025-12-24T20:52:38+00:00

I've created the following page:

<div id="mypage" data-role="page" data-theme="w">
<div id="header" data-role="header" class="ui-noboxshadow ui-header-fixed" data-position="fixed">

</div>
<div data-role="content">       
    <p class="detail-row" style="margin-top: 1em;"><span class="detail-value">{mypage.currentDate}</span></p>
    <p class="detail-row" style="margin-top: 1em;"><span class="detail-value"><img id="myimage_id" src="{mypage.myimage}" /></span></p>
    <p class="detail-row" style="margin-top: 1em;"><span class="detail-value">{mypage.mytitle}</span></p>
    <p class="detail-row"><span class="detail-value">{mypage.mydescription}</span></p>
</div>
<div id="footer" data-role="footer" data-position="fixed" data-theme="g" class="ui-noboxshadow" data-tap-toggle="false">
</div>

It works well (mypage.currentDate,mypage.mytitle, mypage.mydescription placeholders are resolved correctly) except for mypage.image placeholder: it is not resolved (I obtain this url: /%7Bmypage.myimage%7D)

Debugging javascript I saw that mypage.myimage contains the correct value in the model so what's the current syntax in order to resolved my path in img src attribute?

EXAMPLE:

If I try to write:

{mypage.myimage}

it is correctly translated in

/contextroot/images/image.jpg

BUT

if I write it is transformed in <img src="/%7Bmypage.myimage%7D" />

It is not translated, the variable is not resolved!

javascript html jquery-mobile rivets.js
Original Q&A
1

There are 1 answers

0
Elliot Elliot On 2014-01-07T16:57:13+00:00 07 January 2014 at 16:57 BEST ANSWER

You need to write a binder for the src attribute:

rivets.binders.src = function(el, value) {
  el.src = value;
};

Then to use it you write:

<img rv-src="mypage.myimage" />

UDPATE: Looking at the docs I don't think you even need to define the binder. It should default to setting the attribute name after rv-

Related Questions in JAVASCRIPT

  • Using Puppeteer to scrape a public API only when the data changes
  • inline SVG text (js)
  • An array of images and a for loop display the buttons. How to assign each button to open its own block by name?
  • Storing the preferred font-size in localStorage
  • Simple movie API request not showing up in the console log
  • Authenticate Flask rest API
  • Deploying sveltekit app with gunjs on vercel throws cannot find module './lib/text-encoding'
  • How to request administrator rights?
  • mp4 embedded videos within github pages website not loading
  • Scrimba tutorial was working, suddenly stopped even trying the default
  • In Datatables, start value resets to 0, when column sorting
  • How do I link two models in mongoose?
  • parameter values only being sent to certain columns in google sheet?
  • Run main several times of wasm in browser
  • Variable inside a Variable, not updating

Related Questions in HTML

  • How to store a date/time in sqlite (or something similar to a date)
  • How to use custom font during html to pdf conversion?
  • Storing the preferred font-size in localStorage
  • mp4 embedded videos within github pages website not loading
  • Scrimba tutorial was working, suddenly stopped even trying the default
  • Is there any way to glow this bulb image like a real light bulb
  • With non-graphical maps in Leaflet, zoomDelta doesn't work
  • What can I do to improve my coding on both html and css
  • Uncaught TypeError: google.maps.LatLng is not a constructor at init (script.js:7:13)
  • Bootstrap modal not showing at the desired position on a web page when the screen size is smaller
  • Displaying a Movie List on a Website Using Jinja2 and Bootstrap
  • How to redirect to thank you page after submitting a Google form embedded into a Google Site?
  • Storing selected language in localStorage
  • Fences (parenthesis, braces) in HTML and MathML
  • Understanding Scroll Anchoring Behavoir

Related Questions in JQUERY-MOBILE

  • Jquery mobile nav bar items not properly placed
  • jQuery Mobile Autocomplete freeze all the page
  • How can i fix the error i get when i run cordova build android on windows cmd
  • want to make a swipe menu common for all page of my html,
  • JQueryMobile not keeping default style for dynamically appended html
  • class added to div prints extra pages confusion
  • Discord time stamp bug
  • Show different element if the the class has the class active
  • jQuery-Mobile fancy popup box works with jQuery 2.1.3 but breaks with jQuery 2.2.4
  • ASP.NET MVC 5 : model not binding to HttpPostedFileBase from Razor form w/jQuery Mobile
  • Filtering an unordered list with jQuery Mobile 1.5
  • i want to show footer navbar on different situation in JQUERY MOBILE
  • Getting the information of a mobile device by connecting to it
  • Checkbox styles not applying when loading data asynchronously
  • How do I get the content to display in the other menu options?

Related Questions in RIVETS.JS

  • If there a way to add a rivets.js attribute with jQuery?
  • Rivets.js - on-[event] binder and callback function
  • Adding/Removing Cart Items Using Cart.js and Rivets.js
  • Rivetjs | How to bind image link to style="background-image:url()"
  • Rivets.js Cart.js Shopify Product Not removing/updating on cart
  • How to use OR condition in rivetsJS
  • Why is Rivets.js not working on mobile?
  • How can I put RivetsJs Binder to a PHP variable
  • rivets with backbone: calling method (function) on href/onclick attribute
  • Add components dynamically in rivets.js not working
  • Rivets.js IF object exist
  • Rivets formatter when each argument is another formatter
  • Single Bind Statement For Entire Page
  • Django-Dashing Custom Widget HTML Location
  • How do I add custom formatters for rivets in TypeScript?

Popular Questions

  • How do I undo the most recent local commits in Git?
  • How can I remove a specific item from an array in JavaScript?
  • How do I delete a Git branch locally and remotely?
  • Find all files containing a specific text (string) on Linux?
  • How do I revert a Git repository to a previous commit?
  • How do I create an HTML button that acts like a link?
  • How do I check out a remote Git branch?
  • How do I force "git pull" to overwrite local files?
  • How do I list all files of a directory?
  • How to check whether a string contains a substring in JavaScript?
  • How do I redirect to another webpage?
  • How can I iterate over rows in a Pandas DataFrame?
  • How do I convert a String to an int in Java?
  • Does Python have a string 'contains' substring method?
  • How do I check if a string contains a specific word?

Trending Questions

  • UIImageView Frame Doesn't Reflect Constraints
  • Is it possible to use adb commands to click on a view by finding its ID?
  • How to create a new web character symbol recognizable by html/javascript?
  • Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
  • Heap Gives Page Fault
  • Connect ffmpeg to Visual Studio 2008
  • Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
  • How to avoid default initialization of objects in std::vector?
  • second argument of the command line arguments in a format other than char** argv or char* argv[]
  • How to improve efficiency of algorithm which generates next lexicographic permutation?
  • Navigating to the another actvity app getting crash in android
  • How to read the particular message format in android and store in sqlite database?
  • Resetting inventory status after order is cancelled
  • Efficiently compute powers of X in SSE/AVX
  • Insert into an external database using ajax and php : POST 500 (Internal Server Error)
  • Privacy
  • Terms
  • Cookies
  • Homegardensmart
  • Aftereffectstemplates
  • Jogjafile