Jump to content

$Template->Assign_Vars(Array(


bigjoe11a

Recommended Posts

I keep seeing info about this. I haven't been able to find the class for this. Does any one know where I can get the class for this. I need this to set options in my html pages. for links and crap like that. Joe

Link to comment
Share on other sites

I'm not sure what you're asking for. What exactly are you trying do? edit: I see, you're asking for how one can create a template page for HTML that can be filled in with variable values, results from a DB, etc? In that case, it probably wouldn't be that hard to make your own, so it could as specific and flexible for your given application. I believe the kind of functionality you are looking for is commonly found in MVC frameworks, and other general template based sites.

Link to comment
Share on other sites

Well here's a sample. I don't know how to explain this so that you can under stand

$template->assign_vars(array( 'BIRTHDAY_LIST'	=> $birthday_list, 'S_DISPLAY_BIRTHDAY_LIST' => ($config['load_birthdays']) ? true : false, )); <table class="tablebg" cellspacing="1" width="100%"><!--<tr> <th>{L_BIRTHDAYS}</td></tr>--><tr> <td class="row1" valign="top" align="center">   		    <!-- IF S_DISPLAY_BIRTHDAY_LIST and BIRTHDAY_LIST -->		    {L_CONGRATULATIONS}: <strong>{BIRTHDAY_LIST}</strong>		    <!-- ELSE -->		    {L_NO_BIRTHDAYS}		    <!-- ENDIF --> </td></tr></table>

from what I can under stand it addes security to the html pages.My idea is this, <!-- IF IS_USER and IS_BLOG_OWNER --> <a href="">Add Entry</a> <!-- ENDIF --> <a href="">View Blog</a> Does that give you guys an idea. I hope so because I'm lost on this

Link to comment
Share on other sites

well, in my experience when doing a simple MVC for myself, the rendering of the HTML would be a method or something in a render class for a given page. The controller would be responsible for making any DB calls or whatnot to get the information, and would probably pass it into the constructor, and then some sort of render method could be called, which would use the values. Let me see if I can make a basic example, without too much of the MVC overhead to get in the way.

<?php class HomePage{  private $vars = array()    function __construct(args){    $this->vars = args;  }   public function render(){    echo 'Hello ' . $vars['fName'] . ' ' . $var['lName'] . '.  Welcome to the Home Page.';  }}; $user = array(  'fName' => 'John Jacob Jingleheimer',  'lName' => 'Schmidt'); $home = new HomePage($user);$home->render(); ?>

Link to comment
Share on other sites

I'm sorry, You lost me. Below is the class I use for my template system. If you look at line 22, I added some thing new.

class Page {        var $page;    var $_rootref;    function Page($template) {	    if(file_exists($template)) {		    $this->page = join('', file($template));	    }	    else {		    die('Template file ' . $template . ' not found.');	    }    }        function assign_vars($vararray)    {	    foreach($vararray as $key => $val)	    {		    $this->_rootref[$key] = $val;	    }	    return true;    }    function parse($file) {	    ob_start();		    include($file);		    $buffer = ob_get_contents();		    ob_end_clean();	    return $buffer;    }    function replace_tags($tags = array()) {	    if(sizeof($tags) > 0) {		    foreach ($tags as $tag => $data) {			    $data = (file_exists($data)) ? $this->parse($data) : $data;			    $this->page = eregi_replace('{' . $tag . '}', $data, $this->page);		    }	    }	    else {		    die('No tags designated for replacement.');	    }    }    function output() {	    echo $this->page;    }}

below is what I added.

  function assign_vars($vararray)    {	    foreach($vararray as $key => $val)	    {		    $this->_rootref[$key] = $val;	    }	    return true;    }

I got that from the template.php from PHPBB 3.0.9. and I guess this does or I thought it would. Any way no it doesn't work.The idea is to display info from the html page that has some kind of security.

Link to comment
Share on other sites

[color="#008800"] <!-- IF ISUSER_OWNER --><a href="">Add Entry</a> [/color][color="#666600"]<!--[/color][color="#000000"] ENDIF [/color][color="#666600"]-->[/color]

The idea is that is ISUSER_OWNER is the owner of that blog, Then ithis becomes true. The the link to add an entry would show for that user. I could really use some help on this Since I got my javascripts working,

Link to comment
Share on other sites

This isn't a trivial task. My own template engine came in at around 4,000 lines of code. You would probably be better served by using one that already exists, like Smarty, instead of taking pieces from several places and trying to get them to work with each other. For example, your assign_vars function assigns everything to _rootref, but _rootref isn't used anywhere else. The parse function doesn't parse anything, it includes a file and returns the output.

Link to comment
Share on other sites

How do you determine that a user is the owner? Do you have some field in the database for that?
yes I do. I compaire the users id to the users id that created the blog. Then it should return true. I have a class that I call DataManager:: and it does all that for me. There has to be an easy way to do this,
Link to comment
Share on other sites

This isn't a trivial task. My own template engine came in at around 4,000 lines of code. You would probably be better served by using one that already exists, like Smarty, instead of taking pieces from several places and trying to get them to work with each other. For example, your assign_vars function assigns everything to _rootref, but _rootref isn't used anywhere else. The parse function doesn't parse anything, it includes a file and returns the output.
Smarty is too complexed for me. I didn't under stand the doc's or how to use it. I mite try looking on youtube.com for some tutorial videos on it. They mite just help. I don't know. I have so much work in this now. I really don't want to change it.
Link to comment
Share on other sites

That I can beleave, Ever since I started updating my web site. It's been 2 weeks all ready and I still have a month, or a month in 1/2 to go yet. I still have the core to get to gether and then the admin section and then apply all the settings I wanted to add. So this sucks. I wish thers was a better way.

Link to comment
Share on other sites

Guys I can still use some help on this. The idea is to add security right to the html pages them self's I'm still looking for a sample on how to do this so I can add this to my page class. I didn't want to add this right tot the PHP pages, it denotes the idea of using a template. any way I have no idea on how to explain this. So maybe some one will have some ideas. Joe UPDATE;From what I been reading, This just refers to PHPBB forums. So I need an option that will do the same thing.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...