devdavad Posted September 3, 2008 Share Posted September 3, 2008 Hello, I want to incorporate this kind of example that is in the PHPtal manual, but I'm not for sure how to bring it into play with OOP. http://phptal.motion-twin.com/manual/en/split/ar05s02.html#tal-attributes All I have currently is just a recreation of the first example provided <?php require_once 'PHPTAL.php'; $template = new PHPTAL('templates/cssispretty.tmpl'); #want to integrate the following #$left->href = "training.php"; #$left->title = "Training"; #$left->text = "Training"; #$right->href = "ideas.php"; #$right->title = "Ideas.php"; #$right->text = "Ideas.php"; try { echo $template->execute(); } catch (Exception $e) { echo $e; } ?> and my template looks like <div id="container"> <div id="header" class="left"><a href="http://www.sample.com" title="left" tal:attributes="href left/href; title left/title" tal:content="left/text">left</a> </div> <center><img src="images/image006.png" class="header" /></center> <div id="header" class="right"><a href="http://www.sample.com" title="right" tal:attributes="href right/href; title right/title" tal:content="right/text">right</a> </div> </div> So I'm currently getting this error btw. From /var/www/idea/templates/cssispretty.tmpl around line 0 exception 'PHPTAL_Exception' with message 'Unable to find path left in current scope' in /usr/share/php/PHPTAL/Context.php:204 Stack trace: #0 /tmp/tpl_1220483255_1_1_13cssisprett366f164a5ebce3802089745dd671d787.php(14): PHPTAL_Context->__get('left') #1 /usr/share/php/PHPTAL.php(384): tpl_1220483255_1_1_13cssisprett366f164a5ebce3802089745dd671d787(Object(PHPTAL), Object(PHPTAL_Context)) #2 /var/www/idea/index.php(11): PHPTAL->execute() #3 {main} Link to comment https://forums.phpfreaks.com/topic/122637-solved-phptal-and-scope/ Share on other sites More sharing options...
keeB Posted September 4, 2008 Share Posted September 4, 2008 Probably belong in Third Party forums. Link to comment https://forums.phpfreaks.com/topic/122637-solved-phptal-and-scope/#findComment-633314 Share on other sites More sharing options...
devdavad Posted September 5, 2008 Author Share Posted September 5, 2008 Update. I've tried that idea that is modeled after the first example in the phptal manual, but to no avail <?php require_once 'PHPTAL.php'; $template = new PHPTAL('templates/cssispretty.tmpl'); class links { public $href; public $text; function links($href, $text) { $this->href = $href; $this->text = $text; } } $left = new links("www.google.com", "awesome"); $right = new links("www.example2.com", "hope it works"); try { echo $template->execute(); } catch (Exception $e) { echo $e; } ?> [code] <div id="container"> <div id="header" class="left"><a href="http://www.sample.com" title="left" tal:attributes="links/href" tal:content="links/text">left</a> </div> <center><img src="images/image006.png" class="header" /></center> <div id="header" class="right"><a href="http://www.sample.com" title="right" tal:attributes="href right/href; title right/title" tal:content="right/text">right</a> </div> Error message from phptal: 'PHPTAL_Exception' with message 'Unable to find path links in current scope'[/code] Link to comment https://forums.phpfreaks.com/topic/122637-solved-phptal-and-scope/#findComment-634280 Share on other sites More sharing options...
devdavad Posted September 9, 2008 Author Share Posted September 9, 2008 use set to bring them into scope: class links { public $href; public $title; public $text; function links($href, $text, $title) { $this->href = $href; $this->text = $text; $this->title = $title; } } $template->set("left", new links("www.google.com", "awesome", "Awesome")); $template->set("right", new links("www.example2.com", "hope it works", "It won't")); solved, thanks kind people on phptal mailing list Link to comment https://forums.phpfreaks.com/topic/122637-solved-phptal-and-scope/#findComment-637098 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.