Categories > TinyButStrong general >

How to return html code from an object method

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Col
Date: 2009-01-22
Time: 02:50

How to return html code from an object method

I'm sure there's an easy answer to this.

I have a highly configurable internet application of which I won't bore you with details. However the relevant stuff is that they can define a number of database fields to be a certain type (Eg: select, open, timestamp, etc - more will be added in time)

To do this I have defined a TypeFactory:
class TypeFactory {
   public function getType($type) {
      switch (true) {
         case preg_match('/select/', $type): return new SelectType();
         case preg_match('/open/', $type): return new OpenType();
         // add more as needed
      }
   }
}

SelectType:
class SelectType {
   private $_title'

   // superfluous stuff removed
   public function setTitle($title) { $this->_title = $title; }
   public function getTitle($title) { return $this->_title; }
   public function getHTML() {
      return "<select name=$name><option value=opt1>Option1<option value=opt2>Option2></select>";
   }
}

OpenType:
class OpenType {
    private $_title'

    // superfluous stuff removed
    public function setTitle($title) { $this->_title = $title; }
    public function getTitle($title) { return $this->_title; }
    public function getHTML() {
      return "<input type=text>";
   }
}

PHP code:
$tbs = new clsTinyButStrong;
$tbs->LoadTemplate("display.html");
// get requested data from DB
// use the TypeFactory class to convert the data to an array of classes
$tbs->MergeBlock('blkData', $data);
$tbs->Show();

HTML code:
. . .
<table>
[blkData;block=begin]
<tr>
   <td>[blkData.getTitle()]</td>
   <td>[blkData.getHTML()]</td>
</tr>
[blkData;block=end]
</table>

Currently the getHTML() functions are returning the html script and displaying this as raw text. How can I get it to to run the html script from the getHTML function calls?

Thanks for any advice.
By: Jared
Date: 2009-01-22
Time: 03:02

Re: How to return html code from an object method

Does this work?

   <td>[blkData.getTitle();htmlconv=no]</td>
   <td>[blkData.getHTML()htmlconv=no]</td>
By: Col
Date: 2009-01-22
Time: 03:06

Re: How to return html code from an object method

Jared, you're a champion!! Thanks very much.

I obviously misunderstood the htmlconv= functionality as I was thinking the default of htmlconv=yes should do what I want.