+2
Answered

texttemplate

jralston 8 years ago updated by icahill (Administrator) 8 years ago 11
Could someone provide an example of how to use the texttemplate tag?
I'll give a generic example below, however if this doesn't fill your needs, please let us know how and what you are looking at achieving and we'll craft a working example to those needs.

Text templates have a wide variety of uses, from injecting your feed content that may not be HTML encoded into a 'template' of sorts that contains all of your HTML and styling definitions, as well as using text-templates within text-templates to facilitate reuse of blocks of content that may be shared, i.e. having style-definitions (css) that are uses across different data injections.

If you are grabbing HTML content from a feed and placing that within a object (uiwebview), you might use something like this.



<texttemplate name="reader" ><![CDATA[
<html>
<head>
<meta content="width=100%, minimum-scale=1, maximum-scale=1, initial-scale=1" name="viewport">
<style> body{width:80%;margin:0 auto;color:#222222;font-family:Georgia;font-size:17px;line-height:1.5em;background-color:#eeeeee;padding:50px 20px 50px 10px;} h1 {color:#3b3b3c;font-size:28;line-height:1.15em;margin-top:0px;text-align:center;} h2{margin-bottom:10px;color:#d7554b;font-size:15;font-weight:bold;font-family:helvetica;text-transform:uppercase;text-align:center;} h3{font-size:15px;font-weight:normal;color:#898989;text-align:center;border-top:1px solid #bbb;border-bottom:1px solid #bbb;padding:5px 0px;} h3 span{white-space:nowrap;font-style:italic;} p {text-align:justify;}img {max-width:100% !important;} a {color:#444444;border-bottom:1px solid #b2372c;text-decoration:none;} img {display:block;margin:0 auto;margin-bottom:25px;} span.image-rss {display:none;} </style>
</head>
<body>
<h2>[param:category]</h2>
<h1>[param:title]</h1>
<h3> <span>by [param:creator] </span> </h3>
[param:content]
</body>
</html>
]]></texttemplate>


You'll notice in the example above, I am referencing my class parameters being used to inject the feeds content.

Then to make use of this text-template, I use an action like the following:



<action name="assignContent">
<assign property="object:MyWebObjectAlias.html" value="[template:reader.content]" />
</action>


The assign action is looking for the object with an alias of MyWebObjectAlias, so this would be whatever you have named/aliased your web object and then telling the assign to place the content of the value attribute within the 'html' attribute of the named object MyWebObjectAlias.

Breaking down the [template:reader.content], we are calling for a text-template object with the name 'reader' and asking for it's content.

Again, this is the first of many things you can do with the text template. Let us know if we can refine this example for your needs
So then how do I put the content into a panel?
In the example above, you place the content into a web tag within your wire using the assign action.

In the block of code below, you are assigning the attribute "html" from a web tag with an alias named "mywebobjectalias". The value you are assigning is from the texttemplate contents.


<action name="assignContent">
<assign property="object:MyWebObjectAlias.html" value="[template:reader.content]" />
</action>


If this doesn't make sense or you have a specific use case in mind, please let me know. We could possibly look at your project and let you know what you can do to get it working.
I guess this doesn't make sense to me because I want the content to show up on load, so why would I put it in an action? Or maybe I need to know how to make the action happen on load?

I tried this and it didn't work, all that appeared was the word "CONTENT" instead of the value of my texttemplate item:
If you want it to happen on load, then add an attribute to your action tag called oninit="yes" . This will cause your action to trigger when the App is launched.


<action name="assignContent" oninit="yes">
<assign property="object:MyWebObjectAlias.html" value="[template:reader.content]" />
</action>
You will not be able to populate your HTML attribute for your web tag like you have here. The html attribute will not support a value that is an alias unfortuantely. You will need to run it through an action.



<main>
<web name=textgoeshere" alias="TEXTGOES" width="460" height="800" align="center" ypos="20" html="" transparent="yes"></web>
<texttemplate name="reader" ><![CDATA[
<html>
<head>
<meta content="width=100%, minimum-scale=1, maximum-scale=1, initial-scale=1" name="viewport">
<style> body{width:80%;margin:0 auto;color:#222222;font-family:Georgia;font-size:17px;line-height:1.5em;background-color:#eeeeee;padding:50px 20px 50px 10px;} h1 {color:#3b3b3c;font-size:28;line-height:1.15em;margin-top:0px;text-align:center;} h2{margin-bottom:10px;color:#d7554b;font-size:15;font-weight:bold;font-family:helvetica;text-transform:uppercase;text-align:center;} h3{font-size:15px;font-weight:normal;color:#898989;text-align:center;border-top:1px solid #bbb;border-bottom:1px solid #bbb;padding:5px 0px;} h3 span{white-space:nowrap;font-style:italic;} p {text-align:justify;}img {max-width:100% !important;} a {color:#444444;border-bottom:1px solid #b2372c;text-decoration:none;} img {display:block;margin:0 auto;margin-bottom:25px;} span.image-rss {display:none;} </style>
</head>
<body>
<h2>[param:category]</h2>
<h1>[param:title]</h1>
<h3> <span>by [param:creator] </span> </h3>
[param:content]
</body>
</html>
]]></texttemplate>
</main>

<actions>
<action name="assignContent" oninit="yes">
<assign property="object:TEXTGOES.html" value="[template:reader.content]" />
</action>
</actions>

OK, I finally got this to work. I noticed that I couldn't use an alias when I was calling the texttemplate element.

So this worked:
<assign property="object:TEXTGOESHERE.html" value="[template:mycontent.content]" />

but this didn't:
<assign property="object:TEXTGOESHERE.html" value="[template:MYCONTENT.content]" />
correct, eventually we would like to see an alias work in that situation, but our texttemplate is a little more advanced and hasn't gotten the treatment that some of the other tags have.

thanks for sticking it out and getting it to work!
Maybe you could add that to the documentation?