I'm working on a little home brew project and I've found I've been spoiled by working with RoR and more specifically RoR partials
.
My project is entirely client side. So I'm using javascript and HTML5. Now what I would like to do is this: have a home screen template with a container in which I could do something like the
classic <%= yeild %>
tag does in RoR.
I have thought about using iframes
but that seems messy. I have also thought about using xmlHTTP requests to get the file in my javascript and then update the innerHTML
of my content div
with the file stream. I have done this before for personal projects, but it's hacky and I have to flag browsers like Chrome with a --allow-file-access-from-files
tag. Which obviously I can't advise end users to do.
My other thought was to write the html as a javascript string, and then just put different strings as the value of content.innerHTML
but this sounds stupid hard to maintain and just not clean at all.
Ultimately I am even up for writing my own solution (which I would then post here as the answer for anyone else looking) but I wanted to know if there was already a solution out there.
The ultimate end goal behavior would follow this flow:
Main_page:
<div id="main_content">
<!-- this is the yield area -->
</div>
App starts and the file menu.html
is loaded into the yield area
:
<div id="main_content">
<!-- this is the content of menu.html, notice it's like a partial,
there is no body or head or doc type tags, just a list -->
<ul>
<li>Menu item</li>
</ul>
<!-- this is the end of the menu.html content -->
</div>
And finally when they click on Menu item
it loads the contents of menu_item.html
into the content div
replacing the current content (menu.html
).
Some research I already did:
- Div like an iframe?
- Div
src
attribute plugin (looks interesting but runs on webserver) - Stack question about updating div with javascript
- Found a link somewhere that led to Pure This looks like it could do the trick, but seems like it would be difficult to implement for a lot of content (since I don't have anything generating the
json
, I would have to do it all by hand.) - This talks about the
seamless
attribute of iframes, looks promising but only chrome has implemented and even then its bugs have been abandoned.See here for status of webkit development of theseamless
attribute.