TVML: adding new lines to a description text - apple-tv

Experimenting with Apple TV's TVML: I'm using a Product Template, and in the description field I'd like to add carriage returns, to make it look somewhat like a list.
Here is a simple example:
var Template = function() { return `<?xml version="1.0" encoding="UTF-8" ?>
<document>
<productTemplate>
<banner>
<infoList>
</infoList>
<stack>
<title>Big Title</title>
<description>
Line one
Line two
</description>
</stack>
</banner>
</productTemplate>
</document>`
}
I've tried \n, &#xD, &#xA between the lines, and even something like this:
<![CDATA[
Line 1 <br />
Line 2 <br />
]]>
But none of these work. Is there a way to incorporate line breaks in TVML descriptions?

Having this code in a template.xml.js and loading it via the Presenter.js in the TVMLCatalog example from apple:
<stack>
<description>Insert your \n username (tipically your ID)</description>
</stack>
It renders

This also works:
var Template = function() {
const description = `
Line 1
Line 2
`.trim();
return `<?xml version="1.0" encoding="UTF-8" ?>
<document>
<productTemplate>
<banner>
<infoList>
</infoList>
<stack>
<title>Big Title</title>
<description>
${description}
</description>
</stack>
</banner>
</productTemplate>
</document>`
}

Related

How do I pass an object to, or set a variable in a TVML template file I am using?

I'm working with the TVMLCatalog sample files from Apple, and am stuck trying to pass an object to a template file I am loading in the presenter (javascript file). This seems like it should be a totally rudimentary thing to accomplish, but it has me beat.
I have the following, which loads a template with the resource loader, and pushes it to the view.
resourceLoader.loadResource('http://localhost/mytemplate.xml.js',
function(resource) {
if (resource) {
var doc = self.makeDocument(resource);
doc.addEventListener("select", self.load.bind(self));
navigationDocument.pushDocument(doc);
}
}
);
Where do I define an object or set a variable that will be in the document when the template file is loaded in the view?
Yes! You can inject variables into your TVML templates.
First, you have to create a string that contain the same TVML template, and use ${variable} to inject values.
Then, use DOMParser object to convert this string into XML DOM element.
Finally, present the document with help of presentModal method (main object navigationDocument)
Your function will look like this:
function catalogTemplate(title, firstMovie, secMovie) {
var xmlStr = `<?xml version="1.0" encoding="UTF-8" ?>
<document>
<catalogTemplate>
<banner>
<title>${title}</title>
</banner>
<list>
<section>
<listItemLockup>
<title>All Movies</title>
<decorationLabel>2</decorationLabel>
<relatedContent>
<grid>
<section>
<lockup>
<img src="http://a.dilcdn.com/bl/wp-content/uploads/sites/2/2014/03/Maleficent-Poster.jpg" width="250" height="376" />
<title>${firstMovie}</title>
</lockup>
<lockup>
<img src="http://www.freedesign4.me/wp-content/gallery/posters/free-movie-film-poster-the_dark_knight_movie_poster.jpg" width="250" height="376" />
<title>${secMovie}</title>
</lockup>
</section>
</grid>
</relatedContent>
</listItemLockup>
</section>
</list>
</catalogTemplate>
</document>`
var parser = new DOMParser();
var catalogDOMElem = parser.parseFromString(xmlStr, "application/xml");
navigationDocument.presentModal(catalogDOMElem );
}
PS: I used Catalog template as an example. You can use any template
In the onLaunch function, you can call the catalogTemplate function by passing any variable.
App.onLaunch = function(options) {
catalogTemplate("title", "Maleficent.", "The Dark knight");
}
You can add a listener and pass an function to move to another page or trigger an action using addEventListener
function catalogTemplate(title, firstMovie, secMovie, cb) {
var xmlStr = `<?xml version="1.0" encoding="UTF-8" ?>
<document>
<catalogTemplate>
<banner>
<title>${title}</title>
</banner>
<list>
<section>
<listItemLockup>
<title>All Movies</title>
<decorationLabel>2</decorationLabel>
<relatedContent>
<grid>
<section>
<lockup>
<img src="http://a.dilcdn.com/bl/wp-content/uploads/sites/2/2014/03/Maleficent-Poster.jpg" width="250" height="376" />
<title>${firstMovie}</title>
</lockup>
<lockup>
<img src="http://www.freedesign4.me/wp-content/gallery/posters/free-movie-film-poster-the_dark_knight_movie_poster.jpg" width="250" height="376" />
<title>${secMovie}</title>
</lockup>
</section>
</grid>
</relatedContent>
</listItemLockup>
</section>
</list>
</catalogTemplate>
</document>
`
var parser = new DOMParser();
var catalogDOMElem = parser.parseFromString(xmlStr, "application/xml”);
catalogDOMElem.addEventListener("select", cb, false);
navigationDocument.presentModal(catalogDOMElem );
}
Let's create another template just to showcase how we jump to another page by selecting a specific item.
function ratingTemplate(title) {
var xmlStr = `<?xml version="1.0" encoding="UTF-8" ?>
<document>
<ratingTemplate>
<title>${title}</title>
<ratingBadge value="0.8"></ratingBadge>
</ratingTemplate>
</document>`
var parser = new DOMParser();
var ratingDOMElem = parser.parseFromString(xmlStr,"application/xml");
navigationDocument.presentModal(ratingDOMElement);
}
In our onLaunch function.
App.onLaunch = function(options) {
catalogTemplate("title", "Maleficent.", "The Dark knight", function() {
navigationDocument.dismissModal();
ratingTemplate(“rating template title")
});
}
Check this list for more tutorials.

Orbreon - 2 input fields

I've just started with Orbeon forms and cannot figure out the simplest possible thing (I guess).
I want to have two input fields : one for name, the other for surname. Here is my code :
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:xh="http://www.w3.org/1999/xhtml"
xmlns:xf="http://www.w3.org/2002/xforms"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:ev="http://www.w3.org/2001/xml-events"
xmlns:xxf="http://orbeon.org/oxf/xml/xforms"
xmlns:xforms="http://www.w3.org/2002/xforms">
<head>
<xforms:model>
<xforms:instance>
<first-name xmlns=""/>
</xforms:instance>
<xforms:instance>
<second-name xmlns=""/>
</xforms:instance>
</xforms:model>
</head>
<body>
<xforms:input ref="/first-name">
<xforms:label>Sth</xforms:label>
</xforms:input>
<br/>
<xforms:input ref="/second-name">
<xforms:label>Sth2</xforms:label>
</xforms:input>
</body> </html>
For some reason on the page I can see only the first one (first-name input field). What am I doing wrong ?
Here is a working example:
<xh:html
xmlns:xh="http://www.w3.org/1999/xhtml"
xmlns:xf="http://www.w3.org/2002/xforms"
xmlns:xxf="http://orbeon.org/oxf/xml/xforms"
xmlns:ev="http://www.w3.org/2001/xml-events"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xh:head>
<xf:model>
<xf:instance>
<form>
<first-name/>
<last-name/>
</form>
</xf:instance>
</xf:model>
</xh:head>
<xh:body>
<xf:input ref="first-name">
<xf:label>First name:</xf:label>
</xf:input>
<xf:input ref="last-name">
<xf:label>Last name:</xf:label>
</xf:input>
</xh:body>
</xh:html>

Can't fetch mail body using gmail contextual gadget

Here is my manifest.xml file
<?xml version="1.0" encoding="UTF-8" ?>
<ApplicationManifest xmlns="http://schemas.google.com/ApplicationManifest/2009">
 
  <Name>My test gadget</Name>
  <Description>Test Gmail contextual gadgets for mail body</Description>
 
 
<Extension id="MailBodyReaderGadget" type="contextExtractor">
  <Name>Mail Body Reader Gadget</Name>
  <Url>google.com:EmailBodyExtractor</Url>
<Param name="body" value=".*" /> 
  <Triggers ref="mailBodyTextWidget" /> 
  <Scope ref="emailBody" />
  <Container name="mail" />
</Extension>
 
<!-- our GADGET -->
<Extension id="mailBodyTextWidget" type="gadget">
  <Name>Get mail body</Name>
  <Url>http://test.com/spec.xml</Url>
  <Container name="mail" />
</Extension>
 
<!-- gadget Scope -->
<Scope id="emailBody">
  <Url>tag:google.com,2010:auth/contextual/extractor/BODY</Url>
  <Reason>This app will show the mail body text when you click the button "Show Mail Body"</Reason>
</Scope>
</ApplicationManifest>
and spec.xml file
<?xml version="1.0" encoding="UTF-8"?>
<Module>
<ModulePrefs
height="200"
author=""
author_email=""
author_location="US">
        <Require feature="dynamic-height"/>
        <Require feature="google.contentmatch">
            <Param name="extractors">
                google.com:EmailBodyExtractor
            </Param>
        </Require>
    </ModulePrefs>
    <Content type="html" view="card">
<![CDATA[      
<script type="text/javascript">
document.write([
"\<script src='",
("https:" == document.location.protocol) ? "https://" : "http://",
"ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js' type='text/javascript'>\<\/script>"
].join(''));
</script>
<button id="btn">Show Mail Body</button>
<div id="widget" style="heigth:300px;width:500px;">
</div>
    <script>
        matches = google.contentmatch.getContentMatches();
        for (var match in matches) {
          for (var key in matches[match]) {                     
            $("#widget").html(matches[match][key]);           
          }
        }       
    </script>    
    ]]>
  </Content>
</Module>
This is my code, i have been tried to fetch mail subject and from and to email addresses it has been worked. But the main issue is i can't fetch mail body. Is there any solution to fix this?
The answer is to delete the node <Param name="body" value=".*" />
This one had me stuck, as I thought that the <param> node was required to define the name of the output parameter to use in our gadget.
But in fact the MailBodyReaderGadget outputs the parameter of "body" automatically.
So the <Param> node is only used if you wish to filter the output.
As you always want to output the body, you can delete this node entirely.
The reason it is not working at the moment is because the .* filter doesn't match return characters (which will be in the body)

How to get the camera to work with Blackberry Webworks

I am fairly new to webworks. I am trying to get the camera api to work and I keep getting the error:
Error in supported: TypeError: 'undefined' is not an object (evaluating 'blackberry.media.camera')
The page I am trying to use is on a hosted server. The code is as follows:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" id="viewport" content="height=device-height,width=device-width,user-scalable=no" />
<script language="javascript" type="text/JavaScript" >
function takePicture() {
try {
blackberry.media.camera.takePicture(successCB, closedCB, errorCB);
} catch(e) {
alert("Error in supported: " + e);
}
}
function successCB(filePath) {
document.getElementById("path").innerHTML = filePath;
//alert("Succeed: " + filePath);
}
function closedCB() {
// alert("Camera closed event");
}
function errorCB(e) {
alert("Error occured: " + e);
}
</script>
<title>Camera Test Widget</title>
</head>
<body >
<p>Test the Camera by pressing the button below</p>
<b>Take a Picture</b>
<div id="path"></div>
</body>
</html>
And my config.xml file is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<widget xmlns="http://www.w3.org/ns/widgets"
xmlns:rim="http://www.blackberry.com/ns/widgets"
version="1.0.0.0" rim:header="WebWorks Sample">
<access uri="http://www.flyloops.net/" subdomains="true">
<feature id="blackberry.app.event" required="true" version="1.0.0.0"/>
<feature id="blackberry.media.camera" />
</access>
<name>Flyloops.net</name>
<description>This is a sample application.</description>
<content src="index.html"/>
</widget>
The page is hosted at: http://www.flyloops.net/mobile/bb/camera.html
I have been tearing my hair out for the past 3 hours...any help would be greatly appreciated.
If using PlayBook, make sure to have the correct element(s) defined
https://developer.blackberry.com/html5/apis/blackberry.media.camera.html
otherwise, if you are trying to access the blackberry.media.camera API from a remote website, then you need to white list that correctly in config.xml like this:
<access uri="http://www.flyloops.net/" subdomains="true">
<feature id="blackberry.media.camera" />
</access>
What device are you running? The code seems fine and it should work. You can get the eventlogs from the device and see what exceptions are being thrown.
Thanks
Naveen M

jstree not building the tree

I am trying to build a tree from an xml file using jstree. I followed the documentation and looks like it is not working. Here is my code:
<html>
<head>
<title>Demo</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript" src="C:\Users\jstree\jstree_pre1.0_fix_1\jquery.jstree.js"></script>
<Script Language="JavaScript">
$(function () {
$("#demo2").jstree({
"xml_data" : {
"ajax" : {
"url" : "books.xml"
},
"xsl" : "nest"
},
"plugins" : [ "themes", "xml_data" ]
});
});
</Script>
</head>
<body>
</body>
The XML is not formatted in a way that jsTree can include it.
http://www.jstree.com/documentation/xml_data
Two types of XML structures are supported - flat and nested:
<!-- FLAT -->
<root>
<item id="root_1" parent_id="0" state="closed">
<content>
<name><![CDATA[Node 1]]></name>
</content>
</item>
<item id="node_2" parent_id="root_1">
<content>
<name><![CDATA[Node 2]]></name>
</content>
</item>
</root>
<!-- NESTED -->
<root>
<item id="xml_1">
<content><name><![CDATA[Root node 1]]></name></content>
<item id="xml_2">
<content><name><![CDATA[Child node 1]]></name></content>
</item>
</item>
</root>
An alternative is to bring the XML document in and convert it into JSON, then transform it into a valid JSON or HTML data format.
Looks like container(#demo2) is missing. Try adding <div id='demo2'></div> under body tag.
Also make sure the jstree.js file is getting loaded correctly.
There is no such attribute for script called "language" (there may have been, but it's deprecated).
Place your code in script tags like the below code and try again
<script type="text/javascript">
//Your Code Here
</script>
Give a relative path instead of "url" : "books.xml". Replace it with the current path like "url" : "../Content/Xml/books.xml".
That might work.
Regards,
Amrutha